I am trying to write a christmas kris kringle buying list. Ie: Steve buys for Jo, Edward buys for Ally etc. I have 19 people to work with.
Currently I have completed two arrays. I used shuffle to shuffle the original names and have then added them together to store them into a multi dimensional array. It works.. but I have issues with.
The shuffle doesn't care if the person buys their own present. (ie: the multi dimensional array has the same value. ie: [15] => Array ( [0] => Ben[1] => Ben)
how would i go about making exceptions for family members, ie: ben can't buy for Ellen, dave and chilli? and so on.
I have tried looking at various array methods, but i have no more answers.
I would be thinking isomething like this.
if the values are the same, reshuffle and check again. else go to the next value and check again.
<?php
$peoplearray = Array("ben","peter","oscar","jake", "heidi", "Steve", "ed", "matt", "jordan", "gilly" , "Lea", "ellen", "dave", "chilli", "Sean", "Mark", "shane", "ali","dean");
shuffle($peoplearray);
$buying_for = array();
$k=0;
foreach($peoplearray as $value){
print "<BR>";
$buying_for[$k] = $value;
$k++;
}
$peoplearray = Array("ben","peter","oscar","jake", "heidi", "Steve", "ed", "matt", "jordan", "gilly" , "Lea", "ellen", "dave", "chilli", "Sean", "Mark", "shane", "ali","dean");
$total = count($peoplearray);
$result = array();
foreach ($peoplearray as $i => $val) {
$result[] = array($val, $buying_for[$i]);
}
for ($row = 1; $row < $total; $row++) {
echo "<p><b>Pair $row</b></p>";
echo "<ul>";
for ($col = 0; $col < 2; $col++) {
echo " ".$result[$row][$col]." ";
}
echo "</ul>";
}
?>