array_search不适用于嵌套数组

时间:2017-05-26 15:30:17

标签: php

$needle = 'foo';

$haystack = [
    'bar' => [ 'foo' ],
    'baz' => [ 'qux' ]
];

// if 'foo' in of the arrays of $haystack, return its key
// in this case its 'bar'

array_search似乎适用于简单数组。我的情况需要什么?

1 个答案:

答案 0 :(得分:2)

希望这个最简单的会有所帮助

Try this code snippet here

{{1}}