How to search through subarrays efficiently in PHP?

后端 未结 1 665
忘掉有多难
忘掉有多难 2020-12-06 21:31
$arr = array($arr1,$arr2,..);

How to search through $arr to find the one with key1 => \'something\',key2 => \

相关标签:
1条回答
  • 2020-12-06 21:57

    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 讨论(0)
提交回复
热议问题