Created
August 31, 2014 10:29
-
-
Save lukasbestle/12f261293ab8901463dd to your computer and use it in GitHub Desktop.
Fizz Buzz Test in PHP
This file contains hidden or 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 | |
for($i = 1; $i <= 100; $i++) { | |
$found = false; | |
// Divisible by 3 | |
if($i % 3 == 0) { | |
echo 'Fizz'; | |
$found = true; | |
} | |
// Divisible by 5 | |
if($i % 5 == 0) { | |
echo 'Buzz'; | |
$found = true; | |
} | |
// Neither | |
if(!$found) { | |
echo $i; | |
} | |
// Echo trailing newline | |
echo "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment