I have this simple football teams array:
Array
(
[0] => Array
(
[name] => MANCHESTER
[pts] => 8
[gd] => 5
)
[1] => Array
(
[name] => BOURNEMOUTH
[pts] => 3
[gd] => 2
)
[2] => Array
(
[name] => STOKE CITY
[pts] => 2
[gd] => 4
)
[3] => Array
(
[name] => LIVERPOOL
[pts] => 3
[gd] => 5
)
[4] => Array
(
[name] => ARSENAL
[pts] => 9
[gd] => 1
)
)
- name - is teams name
- pts - total points of each team
- gd-is goal difference of each team
I want to sort teams first by pts, then if we have the same pts, sort by gds.
sorting only by pts we have:
function sortByOrder($a, $b){
return $a['pts'] - $b['pts'];
}
usort($this_is_my_array, 'sortByOrder');
Result array is:
ARSENAL (pts:9, gd:1)
MANCHESTER (pts:8, gd:5)
BOURNEMOUTH (pts:3, gd:2)
LIVERPOOL (pts:3, gd:5)
STOKE CITY (pts:2, gd:4)
But for BOURNEMOUTH & LIVERPOOL we have pts repeating, so we need to have this result:
ARSENAL (pts:9, gd:1)
MANCHESTER (pts:8, gd:5)
LIVERPOOL (pts:3, gd:5)
BOURNEMOUTH (pts:3, gd:2)
STOKE CITY (pts:2, gd:4)