2016-07-28 20 views
0

在多維數組值較低我有數組A:
enter image description here
,我已經和輸入文本,在這種情況下,輸入值level,例如它是5。 ,結果必須是2。我想從輸入文本值中找到排列A中的較低級別。我不知道如何進入PHP。幫幫我吧,謝謝獲取PHP

+0

對你想要的更具體。 –

+0

我想,你想在'5'之後的下一個較低的級別,而不是最低的級別,對吧? – RomanPerekhrest

+0

@RomanPerekhrest對! –

回答

1

遍歷的$ arrayA

foreach($arrayA as $array) 
{ 
    // Check each array has level value 2 or not 
    if ($array['level'] == 2) 
    { 
     // found value 
     echo "found the array"; 
    } 
} 
0

所有數組以得到陣列具有特定級別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);