3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = ['a', 'b']; $array2 = ['c', 'd']; $array3 = ['e', 'f']; $arrays = [$array1, $array2, $array3]; function array_cartesian($arrays) { if(count($arrays) == 0) { return array(array()); } $a = array_shift($arrays); $c = array_cartesian($arrays); $r = []; foreach($a as $v) { foreach($c as $p) { $r[] = array_merge(array($v), $p); } } return $r; } print_r(array_cartesian($arrays));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rL8tt
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array1, !1 = $array2, !2 = $array3, !3 = $arrays
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_ARRAY                                       ~7      !0
          4        ADD_ARRAY_ELEMENT                                ~7      !1
          5        ADD_ARRAY_ELEMENT                                ~7      !2
          6        ASSIGN                                                   !3, ~7
   28     7        INIT_FCALL                                               'print_r'
          8        INIT_FCALL                                               'array_cartesian'
          9        SEND_VAR                                                 !3
         10        DO_FCALL                                      0  $9      
         11        SEND_VAR                                                 $9
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function array_cartesian:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 28
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 28
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 26
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/rL8tt
function name:  array_cartesian
number of ops:  31
compiled vars:  !0 = $arrays, !1 = $a, !2 = $c, !3 = $r, !4 = $v, !5 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        COUNT                                            ~6      !0
          2        IS_EQUAL                                                 ~6, 0
          3      > JMPZ                                                     ~7, ->5
   12     4    > > RETURN                                                   <array>
   15     5    >   INIT_FCALL                                               'array_shift'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !1, $8
   16     9        INIT_FCALL_BY_NAME                                       'array_cartesian'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !2, $10
   17    13        ASSIGN                                                   !3, <array>
   19    14      > FE_RESET_R                                       $13     !1, ->28
         15    > > FE_FETCH_R                                               $13, !4, ->28
   20    16    > > FE_RESET_R                                       $14     !2, ->26
         17    > > FE_FETCH_R                                               $14, !5, ->26
   21    18    >   INIT_FCALL                                               'array_merge'
         19        INIT_ARRAY                                       ~16     !4
         20        SEND_VAL                                                 ~16
         21        SEND_VAR                                                 !5
         22        DO_ICALL                                         $17     
         23        ASSIGN_DIM                                               !3
         24        OP_DATA                                                  $17
   20    25      > JMP                                                      ->17
         26    >   FE_FREE                                                  $14
   19    27      > JMP                                                      ->15
         28    >   FE_FREE                                                  $13
   25    29      > RETURN                                                   !3
   26    30*     > RETURN                                                   null

End of function array_cartesian

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.04 ms | 1403 KiB | 20 Q