$fail = 1;
// jap, could be endless ):
while($fail != 0)
{
$fail = 0;
// dead remembers me, what combination i already tried
$dead = array();
// thisweek collects the set (4 games) for this "coloumn"
$thisweek = array();
foreach($b as $k)
{
foreach($k as $lol)
{
// $w saves the teams who have played this week, remember: one team per intervall
$w = array();
$thisweek = array();
// $b is an 2dim array of all combinations (String like "1v2)
$x = $b;
// This shuffels the whole thing... dirty, i know
shuffle($x);
foreach($x as &$lol)
shuffle($lol);
foreach($x as &$i)
{
foreach($i as &$j)
{
if(!empty($j))
{
// get the two teams and see if they already played
list($team1, $team2) = explode("v", $j);
if(!in_array($team1, $w) && !in_array($team2, $w) && !in_array($j, $dead))
{
$dead[] = $j;
$w[] = $team1;
$w[] = $team2;
$thisweek[] = $j;
}
}
}
}
$jointhaweek[] = $thisweek;
if(count($thisweek) < $cnt/2)
{
// and if there are less then 4 matches, reroll ):
$fail = 1;
}
}
}
if($fail == 0)
{
//echo "er hots echt gschofft o.o";
}
}