FizzBuzz - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of FizzBuzz.php
- <?php
- /**
- * @param int $i
- * @return string
- */
- function fb(int $i): string
- {
- if (!$i) return $i;
- $fizz = $i % 3 === 0;
- $buzz = $i % 5 === 0;
- if ($fizz && $buzz) {
- return 'FizzBuzz';
- }
- if ($fizz) {
- return 'Fizz';
- }
- if ($buzz) {
- return 'Buzz';
- }
- return $i;
- }
- function fb2(int $i): string
- {
- if (!$i) return $i;
- $res = '';
- if (!($i % 3)) $res = 'Fizz';
- if (!($i % 5)) $res .= 'Buzz';
- if (!$res) $res = $i;
- return $res;
- }
- function run()
- {
- for ($i = 0; $i <= 100; $i++) {
- print $i . ': ' . fb2($i) . PHP_EOL;
- }
- }
- run();
File Description
- FizzBuzz
- PHP Code
- 24 Feb-2021
- 677 Bytes
You can Share it:
Latest PHP Pastes