3v4l.org

run code in 300+ PHP versions simultaneously
<?php function direct_product(array ...$arrays) { $result = [[]]; foreach ($result as $i => $x) { foreach ($arrays as $j => $y) { $result[$i][$j] = array_merge($x, [$y]); } } return $result; } var_export(direct_product(['A', 'B', 'C'], ['a'], [1, 2])); /* array ( 0 => array ( 0 => 'A', 1 => 'a', 2 => 1, ), 1 => array ( 0 => 'A', 1 => 'a', 2 => 2, ), 2 => array ( 0 => 'B', 1 => 'a', 2 => 1, ), 3 => array ( 0 => 'B', 1 => 'a', 2 => 2, ), 4 => array ( 0 => 'C', 1 => 'a', 2 => 1, ), 5 => array ( 0 => 'C', 1 => 'a', 2 => 2, ), ) */ var_export(direct_product(['A', 'B', 'C'], [], [1, 2])); /* array ( ) */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OuJSU
function name:  (null)
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'var_export'
          1        INIT_FCALL                                               'direct_product'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 <array>
          5        DO_FCALL                                      0  $0      
          6        SEND_VAR                                                 $0
          7        DO_ICALL                                                 
   56     8        INIT_FCALL                                               'var_export'
          9        INIT_FCALL                                               'direct_product'
         10        SEND_VAL                                                 <array>
         11        SEND_VAL                                                 <array>
         12        SEND_VAL                                                 <array>
         13        DO_FCALL                                      0  $2      
         14        SEND_VAR                                                 $2
         15        DO_ICALL                                                 
   60    16      > RETURN                                                   1

Function direct_product:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/OuJSU
function name:  direct_product
number of ops:  22
compiled vars:  !0 = $arrays, !1 = $result, !2 = $x, !3 = $i, !4 = $y, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_VARIADIC                                    !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2      > FE_RESET_R                                       $7      !1, ->19
          3    > > FE_FETCH_R                                       ~8      $7, !2, ->19
          4    >   ASSIGN                                                   !3, ~8
    7     5      > FE_RESET_R                                       $10     !0, ->17
          6    > > FE_FETCH_R                                       ~11     $10, !4, ->17
          7    >   ASSIGN                                                   !5, ~11
    8     8        INIT_FCALL                                               'array_merge'
          9        SEND_VAR                                                 !2
         10        INIT_ARRAY                                       ~15     !4
         11        SEND_VAL                                                 ~15
         12        DO_ICALL                                         $16     
         13        FETCH_DIM_W                                      $13     !1, !3
         14        ASSIGN_DIM                                               $13, !5
         15        OP_DATA                                                  $16
    7    16      > JMP                                                      ->6
         17    >   FE_FREE                                                  $10
    6    18      > JMP                                                      ->3
         19    >   FE_FREE                                                  $7
   11    20      > RETURN                                                   !1
   12    21*     > RETURN                                                   null

End of function direct_product

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.26 ms | 1403 KiB | 19 Q