3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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());
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
$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 =