Skip to content

Instantly share code, notes, and snippets.

@1stvamp
Created February 6, 2013 23:52
Show Gist options
  • Save 1stvamp/4727044 to your computer and use it in GitHub Desktop.
Save 1stvamp/4727044 to your computer and use it in GitHub Desktop.
PHP script to randomly pick winners of PHP Weekly issue #8 giveaway
<?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