0
如何让儿童数组的索引数组看起来像这样PHP search_array:多维数组
Array
(
[1000] => Array
(
[firstName] => Ori
[lastName] => Smith
[children] => Array
(
[0] => 1001
[1] => 1002
[2] => 1003
[3] => 1004
[4] => 1005
[5] => 1006
[6] => 1007
[7] => 1008
[8] => 1009
[9] => 1010
)
)
)
所以如果我给1009的搜索,它应该返回1000
array_search($childrenId, array_column(myArray, 'children'));
我可以告诉你为什么不工作。在你的例子中array_column会给你一个数组内的数组,所以你的array_search甚至不会找到你正在查找的子ID。另外,即使你找到了正确的children数组,我认为array_column会返回一个从零开始的数组 – georaldc