Skip to content

Instantly share code, notes, and snippets.

@mcongrove
Created June 8, 2012 01:07
Show Gist options
  • Save mcongrove/2892798 to your computer and use it in GitHub Desktop.
Save mcongrove/2892798 to your computer and use it in GitHub Desktop.
FizzBuzz
<?php
/**
* Write a script that prints the numbers 1 through 100.
* However, if a number is divisible by 3 then print the word 'Fizz' instead, or the word 'Buzz' if divisible by 5.
* If the number is divisible by both 3 and 5, instead print 'FizzBuzz'.
*/
for($i = 1; $i <= 100; $i++)
{
$output = '';
if($i % 3 === 0)
{
$output .= 'Fizz';
}
if($i % 5 === 0)
{
$output .= 'Buzz';
}
if(strlen($output) === 0)
{
$output .= $i;
}
echo $output . "\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment