Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class LeagueTable
- {
- public function __construct($players)
- {
- $this->standings = array();
- foreach($players as $index => $p)
- {
- $this->standings[$p] = array
- (
- 'index' => $index,
- 'games_played' => 0,
- 'score' => 0
- );
- }
- }
- public function recordResult($player, $score)
- {
- $this->standings[$player]['games_played']++;
- $this->standings[$player]['score'] += $score;
- }
- public function playerRank($rank)
- {
- //
- }
- function array_insert(&$array, $value, $index)
- {
- return $array = array_merge(array_splice($array, max(0, $index - 1)), array($value), $array);
- }
- }
- $table = new LeagueTable(array('Mike', 'Chris', 'Arnold'));
- $table->recordResult('Mike', 5);
- $table->recordResult('Mike', 4);
- $table->recordResult('Arnold', 6);
- $table->recordResult('Chris', 5);
- echo $table->playerRank(1);
- // 1 - Mike
- // 2 - Arnold
- // 3 - Chris
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement