Madatan Posted October 17, 2007 Share Posted October 17, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/73641-creating-league-fixtures/ Share on other sites More sharing options...
chocopi Posted October 17, 2007 Share Posted October 17, 2007 ok i've been messing around with the code for about 10 mins and I think it's what you want <?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 ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/73641-creating-league-fixtures/#findComment-371595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.