1,php搜索多维数组的键值
例子:
如果要查找 bar 3 怎么进行查找呢。有三个结果,而这三个结果都要,看下面的函数:
这个函数就可以把上面要查找到的内容全部返回出键名来
输出结果:
Array ( [0] => Array ( [1] => 2 [2] => a [3] => bb )
[1] => Array ( [1] => 3 [2] => c [3] => dd )
[2] => Array ( [1] => 3 [2] => f [3] => gg )
)
2,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
)
)