3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $scores = array( "Mike" => array(04, 03, 00, 07, 04, 07, 00, 01, 00, 07, 04), "Kyle" => array(07, 01, 00, 03, 04, 01, 00, 07, 03, 04, 04), "Johnny" => array(07, 07, 00, 03, 00, 04, 00, 01, 01, 04, 03), "Will" => array(03, 04, 00, 03, 04, 07, 00, 01, 00, 07, 04), "Vasques" => array(03, 01, 00, 03, 04, 07, 00, 01, 00, 07, 07) ); function cmp($a, $b) { return array_sum($b) - array_sum($a); } uasort($scores, "cmp"); /* function sort_function(array $a, array $b) { $arr1_val = array_sum($a); $arr2_val = array_sum($b); return $arr2_val - $arr1_val; } uasort($scores,"sort_function"); */ print_r($scores);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [Mike] => Array ( [0] => 4 [1] => 3 [2] => 0 [3] => 7 [4] => 4 [5] => 7 [6] => 0 [7] => 1 [8] => 0 [9] => 7 [10] => 4 ) [Kyle] => Array ( [0] => 7 [1] => 1 [2] => 0 [3] => 3 [4] => 4 [5] => 1 [6] => 0 [7] => 7 [8] => 3 [9] => 4 [10] => 4 ) [Will] => Array ( [0] => 3 [1] => 4 [2] => 0 [3] => 3 [4] => 4 [5] => 7 [6] => 0 [7] => 1 [8] => 0 [9] => 7 [10] => 4 ) [Vasques] => Array ( [0] => 3 [1] => 1 [2] => 0 [3] => 3 [4] => 4 [5] => 7 [6] => 0 [7] => 1 [8] => 0 [9] => 7 [10] => 7 ) [Johnny] => Array ( [0] => 7 [1] => 7 [2] => 0 [3] => 3 [4] => 0 [5] => 4 [6] => 0 [7] => 1 [8] => 1 [9] => 4 [10] => 3 ) )