Created
September 7, 2012 02:43
-
-
Save geopet/3662668 to your computer and use it in GitHub Desktop.
PHP FizzBuzz
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
<?php | |
$x = 100; | |
for ( $i = 1; $i <= $x; $i++ ) | |
{ | |
if ( ( $i % 5 == 0 ) && ( $i % 3 == 0 ) ) | |
{ | |
echo "fizzbuzz\n"; | |
} | |
elseif ( $i % 5 == 0 ) | |
{ | |
echo "fizz\n"; | |
} | |
elseif ( $i % 3 == 0 ) | |
{ | |
echo "buzz\n"; | |
} | |
else | |
{ | |
echo $i."\n"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
$x
variable isn't needed. You can just go with$i <= 100
in the for statement.