3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decartProductPair($one, $two) { $result=[]; for($i=0; $i<count($one); $i++) { for($j=0; $j<count($two); $j++) { $result[]=array_merge((array)$one[$i], (array)$two[$j]); } } return array_values($result); } function decartProduct() { $args = func_get_args(); if(!count($args)) { return []; } $result = array_shift($args); while($arg=array_shift($args)) { $result=decartProductPair($result, $arg); } return $result; } $data = array( 2 => array( 0 => 'Body', 1 => 'Face' ), 5 => array( 0 => '*', 1 => '**', 2 => '***' ), 7 => array( 0 => 'Europe', 1 => 'Asia' ) ); $result = array_map(function($set) { return join(',', $set); }, call_user_func_array('decartProduct', array_values($data))); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/32TmP
function name:  (null)
number of ops:  18
compiled vars:  !0 = $data, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN                                                   !0, <array>
   50     1        INIT_FCALL                                               'array_map'
          2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F32TmP%3A50%240'
   53     3        SEND_VAL                                                 ~3
          4        INIT_FCALL                                               'decartproduct'
          5        INIT_FCALL                                               'array_values'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        SEND_ARRAY                                               $4
          9        CHECK_UNDEF_ARGS                                         
         10        DO_FCALL                                      0  $5      
         11        SEND_VAR                                                 $5
         12        DO_ICALL                                         $6      
   50    13        ASSIGN                                                   !1, $6
   55    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function decartproductpair:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 5
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 5
Branch analysis from position: 25
Branch analysis from position: 5
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 7
Branch analysis from position: 21
Branch analysis from position: 7
filename:       /in/32TmP
function name:  decartProductPair
number of ops:  30
compiled vars:  !0 = $one, !1 = $two, !2 = $result, !3 = $i, !4 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->22
    8     5    >   ASSIGN                                                   !4, 0
          6      > JMP                                                      ->18
   10     7    >   INIT_FCALL                                               'array_merge'
          8        FETCH_DIM_R                                      ~9      !0, !3
          9        CAST                                          7  ~10     ~9
         10        SEND_VAL                                                 ~10
         11        FETCH_DIM_R                                      ~11     !1, !4
         12        CAST                                          7  ~12     ~11
         13        SEND_VAL                                                 ~12
         14        DO_ICALL                                         $13     
         15        ASSIGN_DIM                                               !2
         16        OP_DATA                                                  $13
    8    17        PRE_INC                                                  !4
         18    >   COUNT                                            ~15     !1
         19        IS_SMALLER                                               !4, ~15
         20      > JMPNZ                                                    ~16, ->7
    6    21    >   PRE_INC                                                  !3
         22    >   COUNT                                            ~18     !0
         23        IS_SMALLER                                               !3, ~18
         24      > JMPNZ                                                    ~19, ->5
   13    25    >   INIT_FCALL                                               'array_values'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                         $20     
         28      > RETURN                                                   $20
   14    29*     > RETURN                                                   null

End of function decartproductpair

Function decartproduct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 11
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 11
Branch analysis from position: 21
Branch analysis from position: 11
filename:       /in/32TmP
function name:  decartProduct
number of ops:  23
compiled vars:  !0 = $args, !1 = $result, !2 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   FUNC_GET_ARGS                                    ~3      
          1        ASSIGN                                                   !0, ~3
   18     2        COUNT                                            ~5      !0
          3        BOOL_NOT                                         ~6      ~5
          4      > JMPZ                                                     ~6, ->6
   20     5    > > RETURN                                                   <array>
   22     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !0
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !1, $7
   23    10      > JMP                                                      ->16
   25    11    >   INIT_FCALL                                               'decartproductpair'
         12        SEND_VAR                                                 !1
         13        SEND_VAR                                                 !2
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !1, $9
   23    16    >   INIT_FCALL                                               'array_shift'
         17        SEND_REF                                                 !0
         18        DO_ICALL                                         $11     
         19        ASSIGN                                           ~12     !2, $11
         20      > JMPNZ                                                    ~12, ->11
   27    21    > > RETURN                                                   !1
   28    22*     > RETURN                                                   null

End of function decartproduct

Function %00%7Bclosure%7D%2Fin%2F32TmP%3A50%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/32TmP
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
   52     1        INIT_FCALL                                               'join'
          2        SEND_VAL                                                 '%2C'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   53     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F32TmP%3A50%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.82 ms | 1402 KiB | 28 Q