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.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
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:
82.19 ms | 408 KiB | 5 Q