3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array(array(1, 2), array(3, 4), array(5)); function get_combinations($arrays) { $result = array(array()); $count = count($arrays); if(is_array($arrays[0])) { $first_array = $arrays[0]; if($count > 2) { $array_merg = get_combinations(array_slice($arrays, 1)); } else { $array_merg = $arrays[1]; } $tmp = array(); foreach($first_array as $arele1) { foreach($array_merg as $arele2) { if(is_array($arele2)) { $tmp[] = array_merge(array($arele1),$arele2); } else { $tmp[] = array($arele1,$arele2); } } } return $tmp; } else { return $arrays; } } var_dump(get_combinations($a));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9IXF6
function name:  (null)
number of ops:  8
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   33     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'get_combinations'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function get_combinations:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 47
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 44
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 44
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 42
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 42
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 37
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 42
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 44
Branch analysis from position: 24
Branch analysis from position: 44
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9IXF6
function name:  get_combinations
number of ops:  49
compiled vars:  !0 = $arrays, !1 = $result, !2 = $count, !3 = $first_array, !4 = $array_merg, !5 = $tmp, !6 = $arele1, !7 = $arele2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, <array>
    8     2        COUNT                                            ~9      !0
          3        ASSIGN                                                   !2, ~9
    9     4        FETCH_DIM_R                                      ~11     !0, 0
          5        TYPE_CHECK                                  128          ~11
          6      > JMPZ                                                     ~12, ->47
   10     7    >   FETCH_DIM_R                                      ~13     !0, 0
          8        ASSIGN                                                   !3, ~13
   11     9        IS_SMALLER                                               2, !2
         10      > JMPZ                                                     ~15, ->20
   12    11    >   INIT_FCALL_BY_NAME                                       'get_combinations'
         12        INIT_FCALL                                               'array_slice'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 1
         15        DO_ICALL                                         $16     
         16        SEND_VAR_NO_REF_EX                                       $16
         17        DO_FCALL                                      0  $17     
         18        ASSIGN                                                   !4, $17
         19      > JMP                                                      ->22
   14    20    >   FETCH_DIM_R                                      ~19     !0, 1
         21        ASSIGN                                                   !4, ~19
   16    22    >   ASSIGN                                                   !5, <array>
   17    23      > FE_RESET_R                                       $22     !3, ->44
         24    > > FE_FETCH_R                                               $22, !6, ->44
   18    25    > > FE_RESET_R                                       $23     !4, ->42
         26    > > FE_FETCH_R                                               $23, !7, ->42
   19    27    >   TYPE_CHECK                                  128          !7
         28      > JMPZ                                                     ~24, ->37
   20    29    >   INIT_FCALL                                               'array_merge'
         30        INIT_ARRAY                                       ~26     !6
         31        SEND_VAL                                                 ~26
         32        SEND_VAR                                                 !7
         33        DO_ICALL                                         $27     
         34        ASSIGN_DIM                                               !5
         35        OP_DATA                                                  $27
         36      > JMP                                                      ->41
   22    37    >   INIT_ARRAY                                       ~29     !6
         38        ADD_ARRAY_ELEMENT                                ~29     !7
         39        ASSIGN_DIM                                               !5
         40        OP_DATA                                                  ~29
   18    41    > > JMP                                                      ->26
         42    >   FE_FREE                                                  $23
   17    43      > JMP                                                      ->24
         44    >   FE_FREE                                                  $22
   26    45      > RETURN                                                   !5
         46*       JMP                                                      ->48
   28    47    > > RETURN                                                   !0
   31    48*     > RETURN                                                   null

End of function get_combinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.83 ms | 1403 KiB | 20 Q