Created
October 21, 2017 16:06
-
-
Save epatr/b40cbfc8a575adda8fb824a6c6e42844 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 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