3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'vehicle info' => [ 'one' => [ 'submodel' => 'LX', 'engine' => 2.3 ], 'two' => [ 'color' => 'blue', 'year' => 2007, 'wheels' => 4 ], 'three' => [ 'submodel' => 'LX', 'make' => 'Ford', 'model' => 'F-150', 'offroad' => 'No' ] ] ]; $needles = ['submodel', 'offroad']; $result = []; array_walk_recursive( $array, function($value, $key) use ($needles, &$result) { if ( in_array($key, $needles) && !isset($result[$key]) ) { $result[$key] = "$key is $value"; } } ); var_export($result);

preferences:
25.8 ms | 406 KiB | 5 Q