Skip to content

Instantly share code, notes, and snippets.

@bcremer
Last active October 17, 2018 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcremer/4400dc514dcc1e297fa91e2bd867b639 to your computer and use it in GitHub Desktop.
Save bcremer/4400dc514dcc1e297fa91e2bd867b639 to your computer and use it in GitHub Desktop.
FizzBuzz without Conditionals in PHP
<?php
$fizzers = [1, 0, 0, 0];
$buzzers = [2, 0, 0, 0, 0];
$words = ['', 'Fizz', 'Buzz', 'FizzBuzz'];
foreach (range(1, 100) as $i) {
$words[0] = $i;
echo $words[$fizzers[$i % 3] + $buzzers[$i % 5]].PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment