3v4l.org

run code in 300+ PHP versions simultaneously
<?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());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OrB0T
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'fizzbuzz'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                                 
          5      > RETURN                                                   1

Function fizzbuzz:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 11
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 11
Branch analysis from position: 40
Branch analysis from position: 11
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 11
Branch analysis from position: 40
Branch analysis from position: 11
filename:       /in/OrB0T
function name:  fizzbuzz
number of ops:  41
compiled vars:  !0 = $iterations, !1 = $offset, !2 = $fizz, !3 = $buzz, !4 = $fizzbuzz, !5 = $fizz_int, !6 = $buzz_int, !7 = $fizzbuzz_int, !8 = $i, !9 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV_INIT                                        !0      100
          1        RECV_INIT                                        !1      1
          2        RECV_INIT                                        !2      'fizz'
          3        RECV_INIT                                        !3      'buzz'
          4        RECV_INIT                                        !4      'fizzbuzz'
          5        RECV_INIT                                        !5      3
          6        RECV_INIT                                        !6      5
          7        RECV_INIT                                        !7      15
   30     8        ASSIGN                                                   !8, !1
   31     9        ASSIGN                                                   !9, <array>
   33    10      > JMP                                                      ->37
   34    11    >   MOD                                              ~12     !8, !7
         12        IS_EQUAL                                                 ~12, 0
         13      > JMPZ                                                     ~13, ->17
         14    >   ASSIGN_DIM                                               !9
         15        OP_DATA                                                  !4
         16      > JMP                                                      ->31
   35    17    >   MOD                                              ~15     !8, !6
         18        IS_EQUAL                                                 ~15, 0
         19      > JMPZ                                                     ~16, ->23
         20    >   ASSIGN_DIM                                               !9
         21        OP_DATA                                                  !3
         22      > JMP                                                      ->31
   36    23    >   MOD                                              ~18     !8, !5
         24        IS_EQUAL                                                 ~18, 0
         25      > JMPZ                                                     ~19, ->29
         26    >   ASSIGN_DIM                                               !9
         27        OP_DATA                                                  !2
         28      > JMP                                                      ->31
   37    29    >   ASSIGN_DIM                                               !9
         30        OP_DATA                                                  !8
         31    >   CONCAT                                           ~22     '%24i+%3D+', !8
         32        CONCAT                                           ~23     ~22, '+%24offset+%3D+'
         33        CONCAT                                           ~24     ~23, !1
         34        CONCAT                                           ~25     ~24, '+%24iterations+%3D+'
         35        ECHO                                                     ~25
   38    36        PRE_INC                                                  !8
   33    37    >   ADD                                              ~27     !1, !0
         38        IS_SMALLER                                               !8, ~27
         39      > JMPNZ                                                    ~28, ->11
   40    40    > > RETURN                                                   null

End of function fizzbuzz

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.97 ms | 1394 KiB | 16 Q