3v4l.org

run code in 300+ PHP versions simultaneously
<?php function combinations($arr) { $combinations = array_fill(0, count($arr)+1, array()); $combinations[0] = array(''); for ($i = 0, $n = count($arr); $i < $n; ++$i) { for ($l = $n-$i; $l > 0; --$l) { $combinations[$l][] = implode('', array_slice($arr, $i, $l)); } } return $combinations; } $arr = array('d', 'f', 'w', 's'); var_dump(combinations($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/97aIL
function name:  (null)
number of ops:  8
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                   !0, <array>
   16     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'combinations'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function combinations:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 15
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 18
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 15
Branch analysis from position: 36
Branch analysis from position: 15
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 18
Branch analysis from position: 33
Branch analysis from position: 18
filename:       /in/97aIL
function name:  combinations
number of ops:  38
compiled vars:  !0 = $arr, !1 = $combinations, !2 = $i, !3 = $n, !4 = $l
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'array_fill'
          2        SEND_VAL                                                 0
          3        COUNT                                            ~5      !0
          4        ADD                                              ~6      ~5, 1
          5        SEND_VAL                                                 ~6
          6        SEND_VAL                                                 <array>
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !1, $7
    6     9        ASSIGN_DIM                                               !1, 0
         10        OP_DATA                                                  <array>
    7    11        ASSIGN                                                   !2, 0
         12        COUNT                                            ~11     !0
         13        ASSIGN                                                   !3, ~11
         14      > JMP                                                      ->34
    8    15    >   SUB                                              ~13     !3, !2
         16        ASSIGN                                                   !4, ~13
         17      > JMP                                                      ->31
    9    18    >   INIT_FCALL                                               'implode'
         19        SEND_VAL                                                 ''
         20        INIT_FCALL                                               'array_slice'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !2
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $17     
         25        SEND_VAR                                                 $17
         26        DO_ICALL                                         $18     
         27        FETCH_DIM_W                                      $15     !1, !4
         28        ASSIGN_DIM                                               $15
         29        OP_DATA                                                  $18
    8    30        PRE_DEC                                                  !4
         31    >   IS_SMALLER                                               0, !4
         32      > JMPNZ                                                    ~20, ->18
    7    33    >   PRE_INC                                                  !2
         34    >   IS_SMALLER                                               !2, !3
         35      > JMPNZ                                                    ~22, ->15
   12    36    > > RETURN                                                   !1
   13    37*     > RETURN                                                   null

End of function combinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.84 ms | 1403 KiB | 22 Q