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) && !key_exists($key, $result) ) { $result[$key] = "$key is $value"; } } ); var_export($result);
Output for 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array ( 'submodel' => 'submodel is LX', 'offroad' => 'offroad is No', )

preferences:
106.95 ms | 406 KiB | 5 Q