3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = array(8,11,5,6,7); $array2 = array(1,2,3); $arrays = array($array1, $array2); function array_cartesian($arrays) { if(count($arrays) == 0) { return array(array()); } $a = array_shift($arrays); $c = array_cartesian($arrays); $r = array(); 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/h3O3j
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array1, !1 = $array2, !2 = $arrays
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    6     2        INIT_ARRAY                                       ~5      !0
          3        ADD_ARRAY_ELEMENT                                ~5      !1
          4        ASSIGN                                                   !2, ~5
   27     5        INIT_FCALL                                               'print_r'
          6        INIT_FCALL                                               'array_cartesian'
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $7      
          9        SEND_VAR                                                 $7
         10        DO_ICALL                                                 
         11      > 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/h3O3j
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
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        COUNT                                            ~6      !0
          2        IS_EQUAL                                                 ~6, 0
          3      > JMPZ                                                     ~7, ->5
   11     4    > > RETURN                                                   <array>
   14     5    >   INIT_FCALL                                               'array_shift'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !1, $8
   15     9        INIT_FCALL_BY_NAME                                       'array_cartesian'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !2, $10
   16    13        ASSIGN                                                   !3, <array>
   18    14      > FE_RESET_R                                       $13     !1, ->28
         15    > > FE_FETCH_R                                               $13, !4, ->28
   19    16    > > FE_RESET_R                                       $14     !2, ->26
         17    > > FE_FETCH_R                                               $14, !5, ->26
   20    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
   19    25      > JMP                                                      ->17
         26    >   FE_FREE                                                  $14
   18    27      > JMP                                                      ->15
         28    >   FE_FREE                                                  $13
   24    29      > RETURN                                                   !3
   25    30*     > RETURN                                                   null

End of function array_cartesian

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.57 ms | 1402 KiB | 20 Q