Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FizzBuzz 作例:functionを使う
<?php
/**
* @param int $start
* @param int $end
* @return string
*/
function fizzbuzz(int $start, int $end) {
$output = '';
$numbers = range($start, $end);
foreach ($numbers as $number) {
if ($number % 3 === 0) {
$output .= 'Fizz';
} elseif ($number % 5 === 0) {
$output .= 'Buzz';
} elseif ($number % 15 === 0) {
$output .= 'FizzBuzz';
} else {
$output .= $number;
}
$output .= PHP_EOL;
}
return $output;
}
echo fizzbuzz(1, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.