Created
May 19, 2016 13:47
-
-
Save davidstanley01/2e1d3fc87c66caa60db0349ef26a9664 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
<?php | |
function getFizzBuzz($max) { | |
for ($i = 0; $i < $max; $i++) { | |
$string = null; | |
$string = ($i % 15) === 0 && is_null($string) ? 'FizzBuzz' : null; | |
$string = ($i % 3) === 0 && is_null($string) ? 'Fizz' : $string; | |
$string = ($i % 5) === 0 && is_null($string) ? 'Buzz' : $string; | |
yield $string; | |
} | |
} | |
$max = 1000; | |
echo '<ul style="list-style-type:none;">'; | |
foreach (getFizzBuzz($max) as $key => $value) { | |
echo echo sprintf('<li>%s - %s</li>', $key, $value); | |
} | |
echo '</ul>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment