Jump to content

Creating league fixtures


Madatan

Recommended Posts

I have been pondering upon this matter but I just cant figure out a good solution. I would like to recieve some good ideas and help on how to create a pretty simple league fixture code.

 

So lets say I got

 

X vs Y

G vs H

A vs B

 

and I want every team to meet every team 3 times. How should I code to do that automatically and random? Then I want the fixtures inserted into a database table.

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/73641-creating-league-fixtures/
Share on other sites

ok i've been messing around with the code for about 10 mins and I think it's what you want ;D

 

<?php
error_reporting(E_ALL);
$teams1 = array("x","y","g","h","a","b");
$teams2 = $teams1;
$i = 0;
foreach($teams1 as $team1)
{
foreach($teams2 as $team2)
{
	if((array_keys($teams2, $team2)) > (array_keys($teams1, $team1)))
	{
		$matches[$i] = "{$team1} Vs {$team2}";
		$i++;
	}
}
}
for($j = 0; $j <= 2; $j++)
{
shuffle($matches);
$k = $j+1;
echo "<b>Week {$k}</b><br />";
foreach($matches as $match)
{
	echo "{$match} <br />";
}
}
?>

 

Well I hope that helps, it's not the prettiest code ever, but hopefully it does the job :D

 

~ Chocopi

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.