I'm trying to create an app that pairs people from a table.
I'm kind of stuck on setting up the pairings randomly. I have a function that generates random numbers and sticks them into an array based on the number of people I have in the table. See below:
unset($arr);
$arr = array();
while ( count($arr) < $count ) {
$x = mt_rand(1,$count);
if (!in_array($x,$arr)) {
$arr[] = $x;
}
}
But, now that I've got my random numbers, I'm not quite sure how to get the row numbers from the table to match up with the random numbers inside my array.
For instance, let's say I have 4 people in my table...
Sam Adams
Steve Miller
Kevin Smith
Ted Williams
In my array I have 2, 4, 1, 3.
How can I get the Steve match up with Ted, and Sam to match up with Kevin?
Any help is greatly appreciated...
Thanks!
-J