开发者

How to search through subarrays efficiently in PHP?

开发者 https://www.devze.com 2022-12-22 17:10 出处:网络
$arr = array($arr1,$arr2,..); How to search through $arr to fin开发者_Python百科d the one with key1 => \'something\',key2 => \'something else\'You can iterate over a nested array with Iterator
$arr = array($arr1,$arr2,..);

How to search through $arr to fin开发者_Python百科d the one with key1 => 'something',key2 => 'something else'


You can iterate over a nested array with Iterators, e.g.

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

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

Alternatively, have a look at array_walk_recursive

0

精彩评论

暂无评论...
验证码 换一张
取 消