3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrayA = array('A1','A2','A3'); $arrayB = array('B1','B2','B3'); $arrayC = array('C1','C2'); print_r([...combinations([$arrayA, $arrayB, $arrayC])]); function combinations(array $arrays): iterable { if ($arrays === []) { yield []; return; } $head = array_shift($arrays); foreach ($head as $elem) { foreach (combinations($arrays) as $combination) { yield [$elem, ...$combination]; } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Y8clG
function name:  (null)
number of ops:  15
compiled vars:  !0 = $arrayA, !1 = $arrayB, !2 = $arrayC
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    7     3        INIT_FCALL                                               'print_r'
          4        INIT_FCALL_BY_NAME                                       'combinations'
          5        INIT_ARRAY                                       ~6      !0
          6        ADD_ARRAY_ELEMENT                                ~6      !1
          7        ADD_ARRAY_ELEMENT                                ~6      !2
          8        SEND_VAL_EX                                              ~6
          9        DO_FCALL                                      0  $7      
         10        INIT_ARRAY                                       ~8      
         11        ADD_ARRAY_UNPACK                                 ~8      $7
         12        SEND_VAL                                                 ~8
         13        DO_ICALL                                                 
   22    14      > RETURN                                                   1

Function combinations:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 21
Branch analysis from position: 23
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 23
filename:       /in/Y8clG
function name:  combinations
number of ops:  25
compiled vars:  !0 = $arrays, !1 = $head, !2 = $elem, !3 = $combination
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        GENERATOR_CREATE                                         
   10     2        IS_IDENTICAL                                             !0, <array>
          3      > JMPZ                                                     ~4, ->6
   11     4    >   YIELD                                                    <array>
   12     5      > GENERATOR_RETURN                                         
   15     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !0
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !1, $6
   17    10      > FE_RESET_R                                       $8      !1, ->23
         11    > > FE_FETCH_R                                               $8, !2, ->23
   18    12    >   INIT_FCALL_BY_NAME                                       'combinations'
         13        SEND_VAR_EX                                              !0
         14        DO_FCALL                                      0  $9      
         15      > FE_RESET_R                                       $10     $9, ->21
         16    > > FE_FETCH_R                                               $10, !3, ->21
   19    17    >   INIT_ARRAY                                       ~11     !2
         18        ADD_ARRAY_UNPACK                                 ~11     !3
         19        YIELD                                                    ~11
   18    20      > JMP                                                      ->16
         21    >   FE_FREE                                                  $10
   17    22      > JMP                                                      ->11
         23    >   FE_FREE                                                  $8
   22    24      > GENERATOR_RETURN                                         

End of function combinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.19 ms | 1008 KiB | 15 Q