@ 2013-01-07T22:08:37Z <?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;} echo '$i = ' . $i . ' $offset = ' . $offset . ' $iterations = ';
$i++;
}
}
print_r(fizzbuzz());
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 4.3.0 - 4.3.11 , 4.4.0 - 4.4.9 , 5.0.0 - 5.0.5 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 , 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 $i = 1 $offset = 1 $iterations = $i = 2 $offset = 1 $iterations = $i = 3 $offset = 1 $iterations = $i = 4 $offset = 1 $iterations = $i = 5 $offset = 1 $iterations = $i = 6 $offset = 1 $iterations = $i = 7 $offset = 1 $iterations = $i = 8 $offset = 1 $iterations = $i = 9 $offset = 1 $iterations = $i = 10 $offset = 1 $iterations = $i = 11 $offset = 1 $iterations = $i = 12 $offset = 1 $iterations = $i = 13 $offset = 1 $iterations = $i = 14 $offset = 1 $iterations = $i = 15 $offset = 1 $iterations = $i = 16 $offset = 1 $iterations = $i = 17 $offset = 1 $iterations = $i = 18 $offset = 1 $iterations = $i = 19 $offset = 1 $iterations = $i = 20 $offset = 1 $iterations = $i = 21 $offset = 1 $iterations = $i = 22 $offset = 1 $iterations = $i = 23 $offset = 1 $iterations = $i = 24 $offset = 1 $iterations = $i = 25 $offset = 1 $iterations = $i = 26 $offset = 1 $iterations = $i = 27 $offset = 1 $iterations = $i = 28 $offset = 1 $iterations = $i = 29 $offset = 1 $iterations = $i = 30 $offset = 1 $iterations = $i = 31 $offset = 1 $iterations = $i = 32 $offset = 1 $iterations = $i = 33 $offset = 1 $iterations = $i = 34 $offset = 1 $iterations = $i = 35 $offset = 1 $iterations = $i = 36 $offset = 1 $iterations = $i = 37 $offset = 1 $iterations = $i = 38 $offset = 1 $iterations = $i = 39 $offset = 1 $iterations = $i = 40 $offset = 1 $iterations = $i = 41 $offset = 1 $iterations = $i = 42 $offset = 1 $iterations = $i = 43 $offset = 1 $iterations = $i = 44 $offset = 1 $iterations = $i = 45 $offset = 1 $iterations = $i = 46 $offset = 1 $iterations = $i = 47 $offset = 1 $iterations = $i = 48 $offset = 1 $iterations = $i = 49 $offset = 1 $iterations = $i = 50 $offset = 1 $iterations = $i = 51 $offset = 1 $iterations = $i = 52 $offset = 1 $iterations = $i = 53 $offset = 1 $iterations = $i = 54 $offset = 1 $iterations = $i = 55 $offset = 1 $iterations = $i = 56 $offset = 1 $iterations = $i = 57 $offset = 1 $iterations = $i = 58 $offset = 1 $iterations = $i = 59 $offset = 1 $iterations = $i = 60 $offset = 1 $iterations = $i = 61 $offset = 1 $iterations = $i = 62 $offset = 1 $iterations = $i = 63 $offset = 1 $iterations = $i = 64 $offset = 1 $iterations = $i = 65 $offset = 1 $iterations = $i = 66 $offset = 1 $iterations = $i = 67 $offset = 1 $iterations = $i = 68 $offset = 1 $iterations = $i = 69 $offset = 1 $iterations = $i = 70 $offset = 1 $iterations = $i = 71 $offset = 1 $iterations = $i = 72 $offset = 1 $iterations = $i = 73 $offset = 1 $iterations = $i = 74 $offset = 1 $iterations = $i = 75 $offset = 1 $iterations = $i = 76 $offset = 1 $iterations = $i = 77 $offset = 1 $iterations = $i = 78 $offset = 1 $iterations = $i = 79 $offset = 1 $iterations = $i = 80 $offset = 1 $iterations = $i = 81 $offset = 1 $iterations = $i = 82 $offset = 1 $iterations = $i = 83 $offset = 1 $iterations = $i = 84 $offset = 1 $iterations = $i = 85 $offset = 1 $iterations = $i = 86 $offset = 1 $iterations = $i = 87 $offset = 1 $iterations = $i = 88 $offset = 1 $iterations = $i = 89 $offset = 1 $iterations = $i = 90 $offset = 1 $iterations = $i = 91 $offset = 1 $iterations = $i = 92 $offset = 1 $iterations = $i = 93 $offset = 1 $iterations = $i = 94 $offset = 1 $iterations = $i = 95 $offset = 1 $iterations = $i = 96 $offset = 1 $iterations = $i = 97 $offset = 1 $iterations = $i = 98 $offset = 1 $iterations = $i = 99 $offset = 1 $iterations = $i = 100 $offset = 1 $iterations = preferences:dark mode live preview
313.37 ms | 413 KiB | 457 Q