<?php
/**
* @file A fizzbuzz reference implementation.
* @author Brad Czerniak (ao5357@gmail.com)
*/
/**
* Outputs fizzes and buzzes over a loop.
*
* @param int $iterations
* The number of times to iterate over the loop
* @param int $offset
* The number to start at
* @param string $fizz
* The string to output for the first modulo condition, typically 'fizz'.
* @param string $buzz
* The string to output for the second modulo condition, typically 'buzz'.
* @param string $fizzbuzz
* The string to output for the third (usually combined) modulo condition, typically 'fizzbuzz'.
* @param int $fizz_int
* The first modulus
* @param int $buzz_int
* The second modulus
* @param int $fizzbuzz_int
* The third (usually combined) modulus
*
* @return An array of the loop's output
*/
function fizzbuzz($iterations = 100, $offset = 1, $fizz = 'fizz', $buzz = 'buzz', $fizzbuzz = 'fizzbuzz', $fizz_int = 3, $buzz_int = 5, $fizzbuzz_int = 15) {
$i = $offset;
$ret = array();
while($i < ($offset + $iterations)){
if($i % $fizzbuzz_int == 0){ $ret[] = $fizzbuzz;}
elseif($i % $buzz_int == 0){ $ret[] = $buzz;}
elseif($i % $fizz_int == 0){ $ret[] = $fizz;}
else{ $ret[] = $i;}
$i++;
}
}
print_r(fizzbuzz());