Hello,
I'm having difficulties ordering an array and I hope someone can provide some help. I think the problem is that usort compares 2 rows at a time, and I sometimes need to compare on 3 (if there is a 3 way tie).
Here's my array:
Array
(
[1] => Array
(
[team] => 'Bulls'
[points] => 19
[goalsFor] => 20
[goalsAgainst] => 12
)
[2] => Array
(
[team] => 'Lions'
[points] => 8
[goalsFor] => 12
[goalsAgainst] => 8
)
[3] => Array
(
[team] => 'Tigers'
[points] => 8
[goalsFor] => 15
[goalsAgainst] => 12
)
[4] => Array
(
[team] => 'Eagles'
[points] => 8
[goalsFor] => 16
[goalsAgainst] => 15
)
)
[5] => Array
(
[team] => 'Bears'
[points] => 3
[goalsFor] => 7
[goalsAgainst] => 18
)
)
I want to order it first by points (points is accumulated over ALL games played), and then by head-to-head points (points between the tied team games only - which is not stored in this array), and finally by goalsFor. So if array key 2, 3, and 4 all have 8 points, then it needs to pass all 3 of those values to a new function where it finds the point for games between these 3 teams ONLY (head to head points), and order those 3 keys by the head-to-head points in desc order. It needs to then order any that are still tied after head-to-head points, as well as any other teams by goalsFor.
So if I had the following games between the 3 teams that are tied on points:
Eagles vs Tigers: score 3-3
Lions vs Tigers: score 1-4
Lions vs Eagles: score 3-2
Tigers vs Eagles: score 1-2
If each win is worth 2 points and each tie is worth 1 point, then the function will calculate:
Tigers head-to-head points=3
Lions head-to-head points=2
Eagles head-to-head points=3
I want my array to now be sorted as follows:
Array
(
[1] => Array
(
[team] => 'Bulls'
[points] => 19
[goalsFor] => 20
[goalsAgainst] => 12
)
[2] => Array
(
[team] => 'Eagles'
[points] => 8
[goalsFor] => 16
[goalsAgainst] => 15
)
[3] => Array
(
[team] => 'Tigers'
[points] => 8
[goalsFor] => 15
[goalsAgainst] => 12
)
[4] => Array
(
[team] => 'Lions'
[points] => 8
[goalsFor] => 12
[goalsAgainst] => 8
)
[5] => Array
(
[team] => 'Bears'
[points] => 3
[goalsFor] => 7
[goalsAgainst] => 18
)
)
Any ideas is greatly appreciated.
Thank you for your time.
Kind Regards,
Lena