Hi,
I am attempting to generate two sets of random numbers, and have them pair up with no conflitcs.
the end result would look something like this:
1 5
2 3
5 1
4 2
3 4
I have the first set of numbers created, but I can't seem to figure out how to generate a second set and match them as shown above.
<?php
$numbers = array("1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10 ", "11 ", "12 ");
shuffle($numbers);
foreach ($numbers as $number) {
echo "$number ";
echo "<br />";
}
?>
Any help would be appreciated.
Thanks
some help for a beginner
Moderator: General Moderators
Re: some help for a beginner
Is this what you were looking for?
or
-Greg
Code: Select all
$intCount = count($numbers);
for($t=0;$t<$intCount;$t=$t+2) {
echo $numbers[$t},' ',$numbers[$t+1],"\n";
}Code: Select all
$intHalf = count($numbers)/2;
for($t=0;$t<$intHalf;$t++) {
echo $numbers[$t},' ',$numbers[$t+$intHalf],"\n";
}