print_r(fizzBuzz_2(35));
function fizzBuzz_1($n){
	$result = [];
	for ($i = 1; $i <= $n; $i++) {
		$output = "";
		if ($i%3 == 0 && $i%5 == 0) {
			$output = "FizzBuzz";
		}if ($i%3 == 0) {
			$output = "Fizz";
		}if ($i%5 == 0) {
			$output = "Buzz";
		}if (!$output) {
			$output = $i;
		}
		$result[] = $output;
	}
}
// The solution is faster
function fizzBuzz_2($n) {
    $result = [];
    for ($i = 1;  $i <= $n;  $i++) {

        if ($i%15 == 0) {
            $output = "FizzBuzz";
        } else if ($i%3 == 0) {
            $output = "Fizz";
        } else if ($i%5 == 0) {
            $output = "Buzz";
        } else {
            $output = "$i";
        }
        $result[] = $output;
    }
    return $result;
}
by ვაჟა ტყემალაძე
2 years ago
PHP
Problem Solving
0
Pro tip: use ```triple backticks around text``` to write in code fences