3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( "FL_1" => array( "MIC_1" => array( "SP_4" => 7 ), "MIC_13" => array( "SP_16" => 4 ), "MIC_6" => array( "SP_74" => 4 ) ), "FL_2" => array( "MIC_1" => array( "SP_5" => 4 ), "MIC_13" => array( "SP_17" => 4 ), "MIC_6" => array( "SP_75" => 4 ) ), "FL_3" => array( "MIC_1" => array( "SP_5" => 89 ), "MIC_13" => array( "SP_18" => 1 ), "MIC_6" => array( "SP_78" => 21 ) ) ); // find the minimum SP_X value and its key $min_sp = PHP_INT_MAX; $min_key = ''; array_walk_recursive($array, function ($v, $k) use (&$min_sp, &$min_key) { if ($v < $min_sp) { $min_sp = $v; $min_key = $k; } }); echo "$min_key => $min_sp\n"; // find the MIC_X key corresponding to the min SP_X value $mic_key = ''; foreach ($array as $fl) { foreach ($fl as $mic => $sp) { if (isset($sp[$min_key]) && $sp[$min_key] == $min_sp) { $mic_key = $mic; break 2; } } } echo "$mic_key\n"; // filter the array to get all the MIC_X values $out = array_map(function ($fl) use ($mic_key) { return array_filter($fl, function ($mic) use ($mic_key) { return $mic == $mic_key; }, ARRAY_FILTER_USE_KEY); }, $array); print_r($out);
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
SP_18 => 1 MIC_13 Array ( [FL_1] => Array ( [MIC_13] => Array ( [SP_16] => 4 ) ) [FL_2] => Array ( [MIC_13] => Array ( [SP_17] => 4 ) ) [FL_3] => Array ( [MIC_13] => Array ( [SP_18] => 1 ) ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 SP_18 => 1 MIC_13 Array ( [FL_1] => Array ( [MIC_13] => Array ( [SP_16] => 4 ) ) [FL_2] => Array ( [MIC_13] => Array ( [SP_17] => 4 ) ) [FL_3] => Array ( [MIC_13] => Array ( [SP_18] => 1 ) ) )

preferences:
189.47 ms | 403 KiB | 183 Q