0
在多維數組值較低我有數組A:
,我已經和輸入文本,在這種情況下,輸入值level
,例如它是5
。 ,結果必須是2
。我想從輸入文本值中找到排列A中的較低級別。我不知道如何進入PHP。幫幫我吧,謝謝獲取PHP
在多維數組值較低我有數組A:
,我已經和輸入文本,在這種情況下,輸入值level
,例如它是5
。 ,結果必須是2
。我想從輸入文本值中找到排列A中的較低級別。我不知道如何進入PHP。幫幫我吧,謝謝獲取PHP
遍歷的$ arrayA
foreach($arrayA as $array)
{
// Check each array has level value 2 or not
if ($array['level'] == 2)
{
// found value
echo "found the array";
}
}
所有數組以得到陣列具有特定級別2
你可以使用array_filter()一樣,
$result = array_filter($arrayA, function($k) {
return $k['level'] == 2;
});
print_r($result);
而爲使其動態,以獲得最低等級,其parent_ohp_id
爲空然後使用,
$result = array_filter($arrayA, function($k) {
return $k['parent_ohp_id'] == "";// this is the root level because it has no parent id
});
print_r($result);
對你想要的更具體。 –
我想,你想在'5'之後的下一個較低的級別,而不是最低的級別,對吧? – RomanPerekhrest
@RomanPerekhrest對! –