3v4l.org

run code in 300+ PHP versions simultaneously
<?php $multidimensionArray = [ "A2" => [ 0 => "A1", 1 => "A2", 2 => "A3", ], "A1" => [ 0 => "A1", 1 => "A6", 2 => "A5", 3 => "A2", ], "A6" => [ 0 => "A3", ], "A3" => [ 0 => "A3", 1 => "A2", ], "A5" => [ 0 => "A4" ], "A4" => [ 0 => "A4", 1 => "A3", ] ]; $singeArray = [ "A1" => 675.58333333333, "A2" => 1786.75, "A3" => 2897.9166666667, "A4" => 4009.0833333333, "A5" => 5120.25, "A6" => 6231.4166666667, ]; $results = []; foreach ($multidimensionArray as $key => $valueArr) { ## filter out all values of interest from $singleArray $filteredValues = array_filter($singeArray, function ($value, $identifier) use ($valueArr) { return in_array($identifier, $valueArr); }, ARRAY_FILTER_USE_BOTH); ## Here we get the average $results[$key] = array_sum($filteredValues) / count($filteredValues); } print_r($results);
Output for 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
Array ( [A2] => 1786.75 [A1] => 3453.5 [A6] => 2897.9166666667 [A3] => 2342.3333333334 [A5] => 4009.0833333333 [A4] => 3453.5 )
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 Array ( [A2] => 1786.75 [A1] => 3453.5 [A6] => 2897.9166666667 [A3] => 2342.3333333334 [A5] => 4009.0833333333 [A4] => 3453.5 )

preferences:
105.55 ms | 402 KiB | 158 Q