Hello!
I'm on a project making a footballleague, but i've been having trouble with making some fixtures.
This is what i have.
I receive some teams from an Array: (there can be more teams than just 4. The number of team is random and up to the user to choose, but i just need some tip.
I need to create a matchfixture with rounds.
$aTeamArray[0] = 'Manu';
$aTeamArray[1] = 'Liverpool';
$aTeamArray[2] = 'Newcastle';
$aTeamArray[3] = 'Bolton';
$iNumberOfRounds = (count($aTeamArray)*2)-2; //Number of rounds
$iNumberOfMatchesPerRound = count($aTeamArray)/2; //Number of matches each round
In this example, this is the matches that would have been created:
Manu - Liverpool
Manu - Bolton
Manu - Newcastle
Liverpool - Manu
Liverpool - Bolton
Liverpool - Newcastle
Newcastle - Manu
Newcastle - Bolton
Newcastle - Liverpool
Bolton - Manu
Bolton - Liverpool
Bolton - Newcastle
And the final result would look something like this (Wanted result):
Round1:
Manu - Liverpool
Newcastle - Bolton
Round2:
Bolton - Manu
Liverpool - Newcastle
Round3:
Manu - Newcastle
Liverpool - Bolton
Round4:
Bolton - Liverpool
Newcastle - Manu
Round5:
Bolton - Manu
Newcastle - Liverpool
Round6:
Liverpool - Manu
Bolton - Newcastle
I hope you can help me with som solutions or tip.
This is what i tried at first and developed some more code, but i failed 🙁:
foreach($aTeamArray as $home)
{
foreach($aTeamArray as $team)
{
if($home != $team)
{
echo $home.'-'.$team."<br>\n";
}
}
echo "<br>\n";
}
Hope for some good answers and/or solutions 🙂