Created
June 25, 2021 15:12
-
-
Save fajarwz/e11877855591aae3c111b9377c522603 to your computer and use it in GitHub Desktop.
Fizz Buzz using PHP
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 | |
function fizzBuzz($total) { | |
for($i = 1; $i <= $total; $i++) { | |
if($i % 3 == 0 && $i % 5 == 0) { | |
$result .= "Fizz Buzz\n"; | |
} | |
elseif($i % 3 == 0) { | |
$result .= "Fizz\n"; | |
} | |
elseif($i % 5 == 0) { | |
$result .= "Buzz\n"; | |
} | |
else { | |
$result .= $i."\n"; | |
} | |
} | |
return $result; | |
} | |
echo fizzBuzz(100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment