3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr =array( array(1,22,3,6,3), array(4,16,2,10,1), array(11,2,3,5,9), array(3,8,12,4,8) ); function vhall_sort($arr){ $a=$new=array(); foreach($arr as $k=>$v){ $num=array_sum($v); $a[$k]=$num/count($v); } arsort($a); foreach ($a as $k=>$v){ $new[$k] = $arr[$k]; } return $new; } echo '<pre>'; print_r($arr); print_r(vhall_sort($arr));
Output for 4.3.0 - 7.1.0
<pre>Array ( [0] => Array ( [0] => 1 [1] => 22 [2] => 3 [3] => 6 [4] => 3 ) [1] => Array ( [0] => 4 [1] => 16 [2] => 2 [3] => 10 [4] => 1 ) [2] => Array ( [0] => 11 [1] => 2 [2] => 3 [3] => 5 [4] => 9 ) [3] => Array ( [0] => 3 [1] => 8 [2] => 12 [3] => 4 [4] => 8 ) ) Array ( [0] => Array ( [0] => 1 [1] => 22 [2] => 3 [3] => 6 [4] => 3 ) [3] => Array ( [0] => 3 [1] => 8 [2] => 12 [3] => 4 [4] => 8 ) [1] => Array ( [0] => 4 [1] => 16 [2] => 2 [3] => 10 [4] => 1 ) [2] => Array ( [0] => 11 [1] => 2 [2] => 3 [3] => 5 [4] => 9 ) )