Skip to content

Instantly share code, notes, and snippets.

@schnipseljagd
Created October 26, 2012 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schnipseljagd/3958047 to your computer and use it in GitHub Desktop.
Save schnipseljagd/3958047 to your computer and use it in GitHub Desktop.
fizzbuzz in php
function fizzbuzz($number, $output) {
// try with 100 ;-)
if ($number > 97) {
return $output;
}
if ($number % 3 == 0 && $number % 5 == 0) {
$output .= "fizzbuzz\n";
} else if ($number % 3 == 0) {
$output .= "fizz\n";
} else if ($number % 5 == 0) {
$output .= "buzz\n";
} else {
$output .= "$number\n";
}
return fizzbuzz($number + 1, $output);
}
echo fizzbuzz(1, "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment