Click to See Complete Forum and Search --> : Sorting teams for a leaderboard


mateobus
08-08-2006, 05:39 PM
Ok I have teams in arrays and i want to sort them to make a leaderboard. Here are the array values:

$team['name'][index]
$team['conference_points'][index]
$team['goal_differential'][index]
$team['goals_for'][index]
$team['goals_against'][index]
$team['name'][index]

The rules for rankings are as follows. Team with most points is first. If points are the same, the tiebreaker is whoever has the greatest goal differential. If goal diff is the same, its team with the most goals for. How could I do this with PHP? Thanks for all the help.

LimpBagel
08-08-2006, 05:49 PM
If this stuff is in your database it would be very easy to:

SELECT * FROM teams ORDER BY conference_points DESC,
goal_differential DESC,
goals_for DESC,
goals_against ASC

mateobus
08-08-2006, 05:57 PM
...

NogDog
08-08-2006, 08:55 PM
If you don't want to do it via a database, take a look at array_multisort (http://www.php.net/array_multisort). However, after reading that, you may decide it's easier to use a database. :)