Advertisement
Guest User

Untitled

a guest
Jul 11th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2. class LeagueTable
  3. {
  4. public function __construct($players)
  5. {
  6. $this->standings = array();
  7. foreach($players as $index => $p)
  8. {
  9. $this->standings[$p] = array
  10. (
  11. 'index' => $index,
  12. 'games_played' => 0,
  13. 'score' => 0
  14. );
  15. }
  16. }
  17.  
  18. public function recordResult($player, $score)
  19. {
  20. $this->standings[$player]['games_played']++;
  21. $this->standings[$player]['score'] += $score;
  22. }
  23.  
  24.  
  25. public function playerRank($rank)
  26. {
  27. //
  28. }
  29.  
  30. function array_insert(&$array, $value, $index)
  31. {
  32. return $array = array_merge(array_splice($array, max(0, $index - 1)), array($value), $array);
  33. }
  34. }
  35.  
  36. $table = new LeagueTable(array('Mike', 'Chris', 'Arnold'));
  37. $table->recordResult('Mike', 5);
  38. $table->recordResult('Mike', 4);
  39. $table->recordResult('Arnold', 6);
  40. $table->recordResult('Chris', 5);
  41. echo $table->playerRank(1);
  42. // 1 - Mike
  43. // 2 - Arnold
  44. // 3 - Chris
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement