Created
February 6, 2013 23:52
-
-
Save 1stvamp/4727044 to your computer and use it in GitHub Desktop.
PHP script to randomly pick winners of PHP Weekly issue #8 giveaway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$header = null; | |
$subscribers = array(); | |
$handle = fopen(dirname(__FILE__).'/members_PHP_Weekly_Feb_6_2013.csv', 'r'); | |
// fgetcsv is a bit naff, luckily I was able to massage this CSV into an easily parsable format | |
while (($line = fgetcsv($handle, 1000, ",")) !== false) { | |
if ($header === null) { | |
$header = $line; | |
} else { | |
$subscribers[] = array_combine($header, $line); | |
} | |
} | |
// Now $subscribers is a multi-dimensional array with each element being indexed by the keys | |
// in the first row of the CSV, e.g. the header | |
$sd_winner = array_pop(array_splice($subscribers, array_rand($subscribers), 1)); | |
// $subscribers is now missing $sd_winner | |
$dc4d_winner = array_pop(array_splice($subscribers, array_rand($subscribers), 1)); | |
// $subscribers is now missing $dc4d_winner | |
echo "SD winner:\n"; | |
var_dump($sd_winner); | |
echo "\n\nDay Camp 4 Developers Ticket winner 1:\n"; | |
var_dump($dc4d_winner); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment