At this point my script is working but not fully. I managed to pair elements without duplicates, but i cant seem to find any way to repeat the loop so i can get all the possible results. From 20 possible results i get only 16 to 19 results. Any help would be much appreciated. Here's the long code + output
$studentList = array
(
array('up1','up2','up3','up4','up5','up6', 'up7', 'up8' , 'up9' , 'up10'),
array('up1','up2','up3','up4','up5','up6', 'up7', 'up8' , 'up9' , 'up10'),
array('up1','up2','up3','up4','up5','up6', 'up7', 'up8' , 'up9' , 'up10'),
);
//count how many times the user wants to pair students up
$AC = count($studentList);
//Take away one from the count due to the first aray used for setting up the pairs
$AC--;
//count how may users need to be paired
$c = count($studentList[0]);
$totalCount = $AC * $c;
echo $totalCount."<= total count<br>";
for ($b = 1; $b <= $AC; $b++)
{
shuffle($studentList[$b]);
print_R ($studentList[$b]);
echo"<br>";
}
$z = 0;
$r = 1;
$flagReset = 0;
//this will look to make sure the results are random
for ($i = 0; $i < $totalCount; $i++)
{
if ($studentList[0][$z] == $studentList[$r][$z]){}
else
{
$randomArray[$i] = $studentList[0][$z] ."/".$studentList[$r][$z];
}
//echo $z."<= z count|";
if ($i == 0)
{
echo "i am the first $z / $c / $r <br>";
}
if ($z == $c - 1 )
{
if ($i < $totalCount -1 )
{
$r++;
$z= 0;
$flagReset = 1;
}
else
{
$flagReset = 1;
}
}
if ($flagReset == 1)
{
$flagReset = 0;
}
else
{
$z++;
}
if ($i == 19)
{
echo "i am the last $z / $c / $r <br>";
}
array_unique($randomArray, SORT_REGULAR);
$rand = count($randomArray);
}
echo "<br>";
array_unique($randomArray, SORT_REGULAR);
$rand = count($randomArray);
print_r($randomArray);
print $rand;
Output:
20<= total count
Array ( [0] => up8 [1] => up9 [2] => up2 [3] => up4 [4] => up5
[5] => up6 [6] => up3 [7] => up10 [8] => up1 [9] => up7 )
Array ( [0] => up4 [1] => up5 [2] => up8 [3] => up7 [4] => up6 [5] => up1
[6] => up2 [7] => up9 [8] => up10 [9] => up3 )
i am the first 0 / 10 / 1
i am the last 9 / 10 / 2
Array ( [0] => up1/up8 [1] => up2/up9 [2] => up3/up2 [6] => up7/up3
[7] => up8/up10 [8] => up9/up1 [9] => up10/up7 [10] => up1/up4
[11] => up2/up5 [12] => up3/up8 [13] => up4/up7 [14] => up5/up6
[15] => up6/up1 [16] => up7/up2 [17] => up8/up9 [18] => up9/up10
[19] => up10/up3 ) 17