3v4l.org

run code in 300+ PHP versions simultaneously
<?php $collection = array( Array ( 'one' => 10, 'two' => 20, 'three' => 50, 'four' => 80, 'five' => 100 ), Array ( 'three' => 20, 'five' => 20, 'six' => 100, 'seven' => 10 ), Array ( 'one' => 30, 'three' => 30, 'five' => 10, 'eight' => 10 )); //$array = array_merge_recursive($arr1,$arr2,$arr3); $key= "three"; $array = array_column($collection, $key); If(count($array) != 1){ $avg = array_sum($array)/count($array); }Else{ $avg = $array[0]; } Echo $avg;
Output for 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
33.333333333333

preferences:
100.71 ms | 408 KiB | 5 Q