1 php 搜索多维数组的键名
代码如下
function array_search_key($needle, $haystack){
global $nodes_found;
foreach ($haystack as $key1=>$value1) {
if ($key1=== $needle){
$nodes_found[] = $value1;
}
if (is_array($value1)){
array_search_key($needle, $value1);
}
}
return $nodes_found;
}
$result = array_search_key('a', $foo);
print_r($result);
输出结果为如下:
Array
(
[0] => Array
(
[xx] => bar 1
)
[1] => Array
(
[bb] => bar 3
)
[2] => Array
(
[yy] => bar 4
)
)
通过遍历我们可以实现多维数据搜索了。