Because I’m nerdy I decided to write a quick PHP script to handle the assigning of people for my family’s Secret Santa. It’s short, simple, and not-error checked or bug proof in the least.
-
<?php
-
echo "Christmas Secret Santa<br>\n";
-
-
//Build the two arrays. I could in theory use a single array and double it but I was lazy and just defined it twice.
-
$giver = array('Rudolph','Donner','Blitzen','Santa');
-
$receiver = array('Rudolph','Donner','Blitzen','Santa');
-
-
//Randomize the two arrays
-
shuffle($giver);
-
shuffle($receiver);
-
-
//We're going to iterate through the giver array for the individuals.
-
foreach ($giver as $g) {
-
//Make sure that the giver and the receiver are not the same person
-
while ($receiver[0] == $g) {
-
//Shuffle the array to randomize it.
-
shuffle($receiver);
-
}
-
//Grab the first person off the receiver array
-
$r = $receiver[0];
-
//Echo out the result
-
echo $g." – ".$r."<br>\n";
-
//Remove that first person from the array, so we only have ungifted people remaining.
-
$receiver = array_slice($receiver,1);
-
}?>
So nerdy. Maybe later I’ll do it as a javascript snippet.



