How to efficiently search in Subarrays in PHP?

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

How to search through $arr to find one that has key1 => 'something' , key2 => 'something else'

+4
source share
1 answer

You can iterate over a nested array using Iterators , for example

 $iterator = new RecursiveIteratorIterator( new RecursiveArrayIterator($nestedArray), RecursiveIteratorIterator::SELF_FIRST); foreach($iterator as $key => val) { if($key === 'something') { echo $val; } } 

Also see array_walk_recursive

+4
source

Source: https://habr.com/ru/post/1303648/


All Articles