我需要檢查值是否存在於數組中,一旦存在,我需要獲取該對象。檢查是否存在值,並返回多維數組中的對象
Array
(
[0] => Array
(
[_id] => Array
(
[purok] => test
[year] => 2017
[options] => below-1
)
[data] => Array
(
[58cf4935572d6e32900057ab] => Array
(
[age-sex-distribution] => Array
(
[age-range] => Array
(
[options] => below-1
)
[gender] => Array
(
[male-distribution-count] => 12
[female-distribution-count] => 12
)
)
)
)
[date] => 2017-07-08
)
[1] => Array
(
[_id] => Array
(
[purok] => test
[year] => 2017
[options] => toddlers (1-2)
)
[data] => Array
(
[58cf4935572d6e32900057ab12] => Array
(
[age-sex-distribution] => Array
(
[age-range] => Array
(
[options] => toddlers (1-2)
)
[gender] => Array
(
[male-distribution-count] => 12
[female-distribution-count] => 12
)
)
)
)
[date] => 2017-07-08
)
)
如果存在,我需要檢查這個[options] => below-1
。其中一個存在,我需要在陣列中獲得data
。
到目前爲止,我已經嘗試過這一個。
$keySearch = "data.options";
$dataOption = array_search("below-1", array_column($rec, $keySearch));
print_r($dataOption);
但沒有結果。
感謝您提前幫助我。