php - A good way to release fixtures -


hey, problem follows, trying create code set of sporting fixtures created dates on. have 8 teams, 7 rounds of fixtures.

i have generated fixtures, want add date generation on them. if had 7 rounds, put 28 days , make each round 4 days now, 8 days now, etc.

what best way go doing this? thanks

this should want , allows uneven number of teams. dates might not perfect because of rounding down:

    $teams = array("team a","team b","team c","team d","team e", "team f","team g","team h","team i");     $days = 28;     $rounds = count($teams) -1;      //number of days between fixtures     $daysbetweenfixtures = floor($days / $rounds);       $fixtures = array();      for($i =0; $i < count($teams); $i++) {         //calculate date of round of fixtures         $date  = date("d d m y",mktime(0, 0, 0, date("m")  , date("d")+ ($i * $daysbetweenfixtures) , date("y")));          $hasfixturetoday = array();          for($j=$i; $j<$i+count($teams);  $j=$j+2) {             $hometeam = $teams[$j % count($teams)];                      $awayteam = $teams[($j+1) % count($teams)];              if(!in_array($hometeam,$hasfixturetoday) && !in_array($awayteam,$hasfixturetoday)) {                 $fixtures[$date][] = "{$hometeam} vs {$awayteam}";                 $hasfixturetoday[] = $hometeam;                 $hasfixturetoday[] = $awayteam;             }         }     }     print_r($fixtures); 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -