Skip to content

Instantly share code, notes, and snippets.

@Tjorriemorrie
Created March 4, 2014 10:05
Show Gist options
  • Save Tjorriemorrie/9343614 to your computer and use it in GitHub Desktop.
Save Tjorriemorrie/9343614 to your computer and use it in GitHub Desktop.
Looping
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
$range = range(1, 100);
array_walk($range, function($num) {
$val = '';
if (!($num % 3)) {
$val = 'Fizz';
}
if (!($num % 5)) {
$val .= 'Buzz';
}
echo '<p>' . (!$val ? $num : $val) . '</p>';
});
rather return and loop again to print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment