Skip to content

Instantly share code, notes, and snippets.

@davidstanley01
Created May 19, 2016 13:47
Show Gist options
  • Save davidstanley01/2e1d3fc87c66caa60db0349ef26a9664 to your computer and use it in GitHub Desktop.
Save davidstanley01/2e1d3fc87c66caa60db0349ef26a9664 to your computer and use it in GitHub Desktop.
<?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