Skip to content

Instantly share code, notes, and snippets.

@fazleelahhee
fazleelahhee / gist:cf0e06bbdd8adb5510f3329ccdde6b20
Created December 2, 2020 09:33
FizzBuzz problem: Write a short program that prints each number from 1 to 100 on a new line. For each multiple of 3, print "Fizz" instead of the number. For each multiple of 5, print "Buzz" instead of the number. For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number.
<?php
$number = 100;
$findFizzBuzz = function (int $num): string {
$isFizz = $num % 3 == 0;
$isBuzz = $num % 5 == 0;
$fizzBuzz = ($isFizz ? 'fizz' : '') . ($isBuzz ? 'buzz' : '');
return !empty($fizzBuzz) ? $fizzBuzz : (string) $num;
};