Skip to content

Commit 1a81d3e

Browse files
VendinegonSchiele
authored andcommitted
Hash tables for PHP (egonSchiele#39)
1 parent b88af07 commit 1a81d3e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
$book = [];
4+
// an apple costs 67 cents
5+
$book['apple'] = 0.67;
6+
// milk costs $1.49
7+
$book['milk'] = 1.49;
8+
$book['avocado'] = 1.49;
9+
10+
var_dump($book);

05_hash_tables/php/02_check_voter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
$voted = [];
4+
5+
function check_voter($name)
6+
{
7+
global $voted;
8+
if (isset($voted[$name])) {
9+
print "kick them out!\n";
10+
} else {
11+
$voted[$name] = true;
12+
print "let them vote!\n";
13+
}
14+
}
15+
16+
check_voter("tom"); // let them vote!
17+
check_voter("mike"); // let them vote!
18+
check_voter("mike"); // kick them out!

0 commit comments

Comments
 (0)