Created
October 26, 2012 10:26
-
-
Save schnipseljagd/3958047 to your computer and use it in GitHub Desktop.
fizzbuzz in php
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
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