Skip to content

Instantly share code, notes, and snippets.

@ifnull
Created August 3, 2012 23:31
Show Gist options
  • Save ifnull/3252675 to your computer and use it in GitHub Desktop.
Save ifnull/3252675 to your computer and use it in GitHub Desktop.
FizzBuzz in PHP
<?php
/*
* Requirements: No math functions, get single iteration, get iteration range and get infinite iterations
* $start: Starting iteration
* $count: Number of iterations with "0" being infinite.
*/
$start = 10;
$count = 0;
$ugh = array_fill(0, 15, '');
$fizz = array('', '', 'fizz');
$buzz = array('','','','','buzz');
foreach ($ugh as &$val) {
$val = current($fizz).current($buzz);
if(next($fizz) === false){
reset($fizz);
}
if(next($buzz) === false){
reset($buzz);
}
}
reset($ugh);
$i = 1;
$lemniscate = (boolean) $count;
while ($i < $start+$count || !$lemniscate) {
if($i >= $start){
print(sprintf('%d: %s', $i, current($ugh))."\n");
}
if(next($ugh) === false){
reset($ugh);
}
$i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment