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); $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) { //print_r($arele1); foreach($array_merg as $arele2) { print_r($arele2); if(is_array($arele2)) { $tmp[] = array_unshift($arele2,$arele1); } else { $tmp[] = array($arele1,$arele2); } } } print_r($tmp); return $tmp; } var_dump(get_combinations($a));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GATLD
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>
   31     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 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 43
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 43
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 41
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 41
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 41
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 43
Branch analysis from position: 21
Branch analysis from position: 43
filename:       /in/GATLD
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        ASSIGN                                                   !3, ~11
   10     6        IS_SMALLER                                               2, !2
          7      > JMPZ                                                     ~13, ->17
   11     8    >   INIT_FCALL_BY_NAME                                       'get_combinations'
          9        INIT_FCALL                                               'array_slice'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $14     
         13        SEND_VAR_NO_REF_EX                                       $14
         14        DO_FCALL                                      0  $15     
         15        ASSIGN                                                   !4, $15
         16      > JMP                                                      ->19
   13    17    >   FETCH_DIM_R                                      ~17     !0, 1
         18        ASSIGN                                                   !4, ~17
   15    19    >   ASSIGN                                                   !5, <array>
   16    20      > FE_RESET_R                                       $20     !3, ->43
         21    > > FE_FETCH_R                                               $20, !6, ->43
   18    22    > > FE_RESET_R                                       $21     !4, ->41
         23    > > FE_FETCH_R                                               $21, !7, ->41
   19    24    >   INIT_FCALL                                               'print_r'
         25        SEND_VAR                                                 !7
         26        DO_ICALL                                                 
   20    27        TYPE_CHECK                                  128          !7
         28      > JMPZ                                                     ~23, ->36
   21    29    >   INIT_FCALL                                               'array_unshift'
         30        SEND_REF                                                 !7
         31        SEND_VAR                                                 !6
         32        DO_ICALL                                         $25     
         33        ASSIGN_DIM                                               !5
         34        OP_DATA                                                  $25
         35      > JMP                                                      ->40
   23    36    >   INIT_ARRAY                                       ~27     !6
         37        ADD_ARRAY_ELEMENT                                ~27     !7
         38        ASSIGN_DIM                                               !5
         39        OP_DATA                                                  ~27
   18    40    > > JMP                                                      ->23
         41    >   FE_FREE                                                  $21
   16    42      > JMP                                                      ->21
         43    >   FE_FREE                                                  $20
   27    44        INIT_FCALL                                               'print_r'
         45        SEND_VAR                                                 !5
         46        DO_ICALL                                                 
   28    47      > RETURN                                                   !5
   29    48*     > RETURN                                                   null

End of function get_combinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.93 ms | 1403 KiB | 22 Q