-
Notifications
You must be signed in to change notification settings - Fork 0
/
secretsanta.php
33 lines (29 loc) · 954 Bytes
/
secretsanta.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
$girls = array(
array('Nat','test@test.com'),
array('Gentry','test@test.com'),
array('Donny','test@test.com'),
array('Gee','test@test.com')
);
$dupe = $girls;
shuffle($dupe);
$matches = array();
while(count($dupe) > 0) {
if( $dupe[0][0] != $girls[0][0] ) {
$santa = array_shift($girls); // dupe
$secret = array_shift($dupe); // girl
$matches[] = array($santa, $secret);
} else if( count($dupe) == 1 && $dupe[0][0] == $girls[0][0] ) {
$santa = array_shift($girls); // steal
$secret = $matches[0][1]; // normal
$matches[0][1] = array_shift($dupe); // last girl swapped
$matches[] = array($santa, $secret); // last match
} else {
shuffle($dupe);
}
}
foreach($matches as $match) {
echo $match[0][0] . ' at ' . $match[0][1] . ' buyz for ' . $match[1][0] . '<br/>';
// send email
echo mail ( $match[0][1] , 'Secret Santa' , 'Hey ' . $match[0][0] . ', you buy for ' . $match[1][0] . '. Ignore previous emails. ' );
}