I have an array of an unknown length which will always have an evenly divisible amount of values, for example:
print_r($initialarray);
Array ( [0] => 30 [1] => 31 [2] => 32 [3] => 33 [4] => 34 [5] => 35 )
I need to create sets:
Set 1: 30 v 35; 31 v 34; 32 v 33; Set 2: 30 v 34; 31 v 33; 32 v 35; Set 3: 30 v 33; 31 v 32; 34 v 35; Set 4: 30 v 32; 33 v 34; 31 v 35; Set 5: 30 v 31; 32 v 34; 33 v 35;
The order of the values are divide by v to indicate they are a set. The ordering of the values in the set does not matter (I put that together at random out of my head). As you can see there can not be duplicate sets matching in any other set or within the same set.
I have tried many different things to come up with something that works. The closest I've gotten was putting the initial values into a cascading array containing all possible valid matchups:
Array ( [0] => Array ( [0] => 35 [1] => 31 ) [1] => Array ( [0] => 34 [1] => 31 ) [2] => Array ( [0] => 33 [1] => 31 ) [3] => Array ( [0] => 32 [1] => 31 ) )
Array ( [0] => Array ( [0] => 35 [1] => 32 ) [1] => Array ( [0] => 34 [1] => 32 ) [2] => Array ( [0] => 33 [1] => 32 ) )
Array ( [0] => Array ( [0] => 35 [1] => 33 ) [1] => Array ( [0] => 34 [1] => 33 ) )
Array ( [0] => Array ( [0] => 35 [1] => 34 ) )
These values are arrays within one array called $sched. I left 30 out of the array.. oops
The numbers are teams. Each team needs to play each team once. The schedule will be set so that each team only plays one game each week. The schedule needs to be set over several weeks to allow all the games to be played without a team playing more than once in a week.
I have already used a permutations function and that is how I came up with array above which doesn't have identical match ups. I need to now figure out how to output the schedule as shown in the Sets above. (keeping in mind that the order the example is in doesn't matter as long as no team plays twice in the same set)
$count = count($initialarray);
$recount = $count -1;
for($u=0; $u < $count;$u++){
for($d=0;$d<$recount;$d++){
$vs[$u][$d] = $sched[$d][$u];
}
$recount -= 1;
}
So that didn't work, I am complicating this beyond what it should be and I can't wrap my head around the issue anymore. Any help at all, even it means starting over, will be greatly appreciated!