Created
February 21, 2012 17:45
-
-
Save susanBuck/1877647 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Random Drawing</title> | |
<?php | |
# Who are our contestants? | |
$contestants["Bob"] = ""; | |
$contestants["Frank"] = ""; | |
$contestants["Emily"] = ""; | |
$contestants["Bo"] = ""; | |
$contestants["Sandy"] = ""; | |
$contestants["Liz"] = ""; | |
$contestants["Joey"] = ""; | |
# Pick and print a winning number | |
$how_many_contestants = count($contestants); | |
$winning_number = rand(1,$how_many_contestants); | |
# Loop through contestants, seeing if any won | |
foreach($contestants as $index => $this_contestant) { | |
# Generate a random number | |
$random_number = rand(1,$how_many_contestants); | |
# See if their generated random number mathches the winning number | |
if($random_number == $winning_number) { | |
$contestants[$index] = "Winner!"; | |
} | |
else { | |
$contestants[$index] = "Loser!"; | |
} | |
} | |
?> | |
</head> | |
<body> | |
Refresh to play again <br><br> | |
</div> | |
The winning number is <?=$winning_number?>!<br><br> | |
<? foreach($contestants as $index => $contestant): ?> | |
<?=$index?> is a <?=$contestant?><br> | |
<? endforeach ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment