Skip to content

Instantly share code, notes, and snippets.

@firegate666
Last active December 27, 2015 00:59
Show Gist options
  • Save firegate666/7241211 to your computer and use it in GitHub Desktop.
Save firegate666/7241211 to your computer and use it in GitHub Desktop.
This is a free configurable implementation of the fizzbuzz problem
<?php
$config = array(
'fizz' => 3,
'buzz' => 5,
/*
'prim' => function($num) {
return in_array($num, array(1, 2, 3, 5, 7, 11, 13, 17, 19, 23));
}
*/
);
for ($i = 1; $i < 101; $i++) {
$output = '';
foreach ($config as $buzzword => $divider) {
$is_callable = is_callable($divider);
if (($is_callable && $divider($i)) || (!$is_callable && $i % $divider === 0)) {
$output .= $buzzword;
}
}
if ($output === '') {
$output = $i;
}
printf('%s ', $output);
}
echo PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment