3v4l.org

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

End of function array_cartesian

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.98 ms | 1403 KiB | 20 Q