Skip to content

Instantly share code, notes, and snippets.

@myinitialsaretk
Created November 15, 2012 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myinitialsaretk/4079479 to your computer and use it in GitHub Desktop.
Save myinitialsaretk/4079479 to your computer and use it in GitHub Desktop.
I can't believe somebody actually asked me to solve fizzbuzz.
<pre>
<?php
/*
FizzBuzz Solution
-----------------
Write a program that prints out the numbers from A through B, but…
For numbers that are multiples of 3, print “Fizz” instead of the number.
For numbers that are multiples of 5, print “Buzz” instead of the number
For numbers that are multiples of both 3 and 5, print “FizzBuzz” instead of the number.
*/
define("A",1);
define("B",100);
function is_multiple_of_n($integer, $n)
{
return ($integer % $n == 0);
}
for($i = A; $i <= B; $i++)
{
$output = '';
if ( !is_multiple_of_n($i,3) && !is_multiple_of_n($i,5) )
{
$output .= $i;
}
else
{
if ( is_multiple_of_n($i,3))
{
$output .= "Fizz";
}
if ( is_multiple_of_n($i,5))
{
$output .= "Buzz";
}
}
echo $output . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment