fork download
  1. <?php
  2.  
  3. // test data
  4. $team_data[] = array("team-A", 5, -5, 0);
  5. $team_data[] = array("team-B", 7, 3, 50);
  6. $team_data[] = array("team-C", 8, 3, 50);
  7. $team_data[] = array("team-D", 10, 4, 85);
  8. $team_data[] = array("team-E", 10, 4, 90);
  9. $team_data[] = array("team-F", 10, 5, 100);
  10.  
  11. // compare function
  12. function team_comp($a, $b) {
  13. if ($a[1] != $b[1]) {
  14. return $b[1] - $a[1];
  15. } else if ($a[2] != $b[2]) {
  16. return $b[2] - $a[2];
  17. } else {
  18. return $b[3] - $a[3];
  19. }
  20. }
  21.  
  22. //
  23. function print_team($teams) {
  24. foreach ($teams as $t) {
  25. echo $t[0] . " : " . $t[1] . " " . $t[2] . " " . $t[3] . "\n";
  26. }
  27. }
  28.  
  29. echo "------------- before ----------\n";
  30. print_team($team_data);
  31.  
  32. usort($team_data, "team_comp");
  33.  
  34. echo "------------- after ----------\n";
  35. print_team($team_data);
  36.  
  37.  
Success #stdin #stdout 0.02s 24400KB
stdin
Standard input is empty
stdout
------------- before ----------
team-A : 5 -5 0
team-B : 7 3 50
team-C : 8 3 50
team-D : 10 4 85
team-E : 10 4 90
team-F : 10 5 100
------------- after ----------
team-F : 10 5 100
team-E : 10 4 90
team-D : 10 4 85
team-C : 8 3 50
team-B : 7 3 50
team-A : 5 -5 0