3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testOne = array ( 'Smith'=> 98, 'Johnson' => 67, ); $testTwo = array ( 'Smith'=> 100, 'Johnson' => 85, ); $testThree = array ( 'Smith'=> 78, 'Johnson' => 92, ); $testFour = array ( 'Smith'=> 91, 'Johnson' => 88, ); $total = [$testOne, $testTwo, $testThree, $testFour]; Foreach($total[0] as $name => $val){ $averages[$name] = array_sum(array_column($total, $name))/count($total); } var_dump($averages);

preferences:
26.31 ms | 406 KiB | 5 Q