PHP Classes

PHP League Fixtures: Create a schedule of games to be played by teams

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 439 All time: 6,263 This week: 73Up
Version License PHP version Categories
fixture 1.0GNU General Publi...5.0Algorithms, PHP 5, Games
Description 

Author

This class can create a schedule of games to be played by teams.

It takes an array with a list of teams and returns another array list of games to be play by the teams on each round.

The class supports lists with a number of teams that may even or odd. In the latter case one team will not play in each round.

Picture of David Hernandez
  Performance   Level  
Name: David Hernandez <contact>
Classes: 1 package by
Country: Mexico Mexico

Example

<?php
require_once './Fixture.php';
//Example with a pair number of teams
$teams = array("Germany", "England", "France", "Brasil", "Mexico", "Japan", "Nigeria", "Spain");
$fixPair = new Fixture($teams);
$schedule = $fixPair->getSchedule();
//show the rounds
$i = 1;
foreach(
$schedule as $rounds){
    echo
"<h3>Round {$i}</h3>";
    foreach(
$rounds as $game){
        echo
"{$game[0]} vs {$game[1]}<br>";
    }
    echo
"<br>";
   
$i++;
}
echo
"<hr>";


//Example with a odd number of teams
$otherTeams = array("Portugal", "Argentina", "South Korea", "Australia", "Egypt");
$fixOdd = new Fixture($otherTeams);
$games = $fixOdd->getSchedule();
$i = 1;
foreach(
$games as $rounds){
   
$free = "";
    echo
"<h3>Round {$i}</h3>";
    foreach(
$rounds as $match){
        if(
$match[0] == "free this round"){
           
$free = "<span style='color:red;'>{$match[1]} is {$match[0]}</span><br>";
        }elseif(
$match[1] == "free this round"){
           
$free = "<span style='color:red;'>{$match[0]} is {$match[1]}</span><br>";
        }else{
            echo
"{$match[0]} vs {$match[1]}<br>";
        }
    }
    echo
$free;
    echo
"<br>";
   
$i++;
}


  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file example.php Example Example
Plain text file Fixture.php Class Main class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:439
This week:0
All time:6,263
This week:73Up