1. $fail = 1;
  2. // jap, could be endless ):
  3. while($fail != 0)
  4. {
  5.     $fail = 0;
  6.    
  7.     // dead remembers me, what combination i already tried
  8.     $dead = array();
  9.    
  10.     // thisweek collects the set (4 games) for this "coloumn"
  11.     $thisweek = array();
  12.     foreach($b as $k)
  13.     {
  14.         foreach($k as $lol)
  15.         {
  16.             // $w saves the teams who have played this week, remember: one team per intervall
  17.             $w = array();
  18.             $thisweek = array();
  19.            
  20.             // $b is an 2dim array of all combinations (String like "1v2)
  21.            
  22.             $x = $b;
  23.            
  24.            
  25.            
  26.             // This shuffels the whole thing... dirty, i know
  27.             shuffle($x);
  28.             foreach($x as &$lol)
  29.                 shuffle($lol);
  30.             foreach($x as &$i)
  31.             {
  32.                
  33.                 foreach($i as &$j)
  34.                 {
  35.                     if(!empty($j))
  36.                     {
  37.                         // get the two teams and see if they already played
  38.                         list($team1, $team2) = explode("v", $j);
  39.                         if(!in_array($team1, $w) && !in_array($team2, $w) && !in_array($j, $dead))
  40.                         {
  41.                             $dead[] = $j;
  42.                             $w[] = $team1;
  43.                             $w[] = $team2;
  44.                             $thisweek[] = $j;
  45.                            
  46.                         }
  47.                     }
  48.                 }
  49.             }
  50.             $jointhaweek[] = $thisweek;
  51.             if(count($thisweek) < $cnt/2)
  52.             {
  53.                 // and if there are less then 4 matches, reroll ):
  54.                 $fail = 1;
  55.             }
  56.         }
  57.        
  58.     }
  59.     if($fail == 0)
  60.     {
  61.         //echo "er hots echt gschofft o.o";
  62.    
  63.    
  64.     }
  65. }