如何在PHP中有效地搜索子数组?

时间:2010-03-10 10:29:33

标签: php arrays

$arr = array($arr1,$arr2,..);

如何搜索$arr以查找key1 => 'something'key2 => 'something else'

的{{1}}

1 个答案:

答案 0 :(得分:4)

您可以使用Iterators迭代嵌套数组,例如

$iterator = new RecursiveIteratorIterator(
                new RecursiveArrayIterator($nestedArray), 
                RecursiveIteratorIterator::SELF_FIRST);

foreach($iterator as $key => val) {
    if($key === 'something') {
        echo $val;
    }
}

或者,请查看array_walk_recursive