I have the following array that I need to have sorted from highest score to lowest.
Array
(
[0] => Array
(
[team id] => 5
[score] => 52
[fouls] => 0
)
[1] => Array
(
[team id] => 4
[score] => 47
[fouls] => 0
)
[2] => Array
(
[team id] => 8
[score] => 46
[fouls] => 6
)
[3] => Array
(
[team id] => 1
[score] => 46
[fouls] => 5
)
[4] => Array
(
[team id] => 9
[score] => 46
[fouls] => 3
)
)
The array above has been sorted already with this function:
function sortByOrder($a, $b){
$Return = $b['score'] - $a['score'];
return $Return;
}
usort($Array, 'sortByOrder');
Which seems to work fine since the array with the highest score goes up the list.
However, some teams have equal scores but have committed some fouls. How can I adjust the function to also take the fouls into account when a score equals another score? The team with the least fouls should be placed higher.
Looking forward for creative solutions!
Thanks in advance.
if($b['score'] == $a['score'])something like this in sortByOrder?