05-04-2009, 02:20 AM
|
#1 (permalink)
|
|
The Wanderer
Join Date: May 2009
Posts: 23
Thanks: 4
|
99 beers of bottle challenge
just to have some fun and tried to beat the 99 beer bottle challenge...
visit http://99-bottles-of-beer.net/language-php-1825.html for more information.
Code:
<?php
/* 99 bottles of beer by foobarph (http://rllqph.wordpress.com) */
for ($i = 99; $i >= 0; $i--) {
$bottles = $i;
$usedBottles = $i-1;
if ($i == 0) {
$action = "Go to the store and buy some more, ";
$sBottles = "bottle";
$bottles = "no more";
}
if ($i == 1) {
$sBottles = "bottle";
}
if ($i > 1) {
$action = "Take one down and pass it around, ";
$sBottles = "bottles";
}
if ($usedBottles == 0) {
$usedBottles = "no more";
}
if ($usedBottles < 0) {
$usedBottles = "99";
$sBottles = "bottles";
}
echo ucfirst($bottles) . " ". $sBottles ." of beer on the wall, ". $bottles ." ". $sBottles ." of beer.<br />";
echo $action . $usedBottles ." ". $sBottles ." of beer on the wall.<br /><br />";
}
?>
any comments on how i can improve this code? feel free to post them here. thanks! :)
|
|
|
|