Skip to content

Instantly share code, notes, and snippets.

@geopet
Created September 7, 2012 02:43
Show Gist options
  • Save geopet/3662668 to your computer and use it in GitHub Desktop.
Save geopet/3662668 to your computer and use it in GitHub Desktop.
PHP FizzBuzz
<?php
$x = 100;
for ( $i = 1; $i <= $x; $i++ )
{
if ( ( $i % 5 == 0 ) && ( $i % 3 == 0 ) )
{
echo "fizzbuzz\n";
}
elseif ( $i % 5 == 0 )
{
echo "fizz\n";
}
elseif ( $i % 3 == 0 )
{
echo "buzz\n";
}
else
{
echo $i."\n";
}
}
?>
@geopet
Copy link
Author

geopet commented Sep 7, 2012

The $x variable isn't needed. You can just go with $i <= 100 in the for statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment