Files
grokking_algorithms/05_hash_tables/php/02_check_voter.php
2017-11-13 08:12:01 -08:00

19 lines
338 B
PHP

<?php
$voted = [];
function check_voter($name)
{
global $voted;
if (isset($voted[$name])) {
print "kick them out!\n";
} else {
$voted[$name] = true;
print "let them vote!\n";
}
}
check_voter("tom"); // let them vote!
check_voter("mike"); // let them vote!
check_voter("mike"); // kick them out!