Skip to content

Instantly share code, notes, and snippets.

@epatr
Created October 21, 2017 16:06
Show Gist options
  • Save epatr/b40cbfc8a575adda8fb824a6c6e42844 to your computer and use it in GitHub Desktop.
Save epatr/b40cbfc8a575adda8fb824a6c6e42844 to your computer and use it in GitHub Desktop.
<?php
function fizzbuzz ($first, $last) {
$current = $first;
while ($current <= $last) {
if (($current % 3 == 0) && ($current % 5 == 0)) {
yield "fizzbuzz";
} else if ($current % 3 == 0) {
yield "fizz";
} else if ($current % 5 == 0) {
yield "buzz";
} else {
yield $current;
}
$current++;
}
}
foreach (fizzbuzz(1,100) as $number) {
echo $number . '<br>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment