3v4l.org

run code in 300+ PHP versions simultaneously
<?php function direct_product(array ...$arrays) { $result = [[]]; foreach ($result as $i => $x) { foreach ($arrays as $y) { $result[$i] = 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/EkJ2Y
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 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/EkJ2Y
function name:  direct_product
number of ops:  20
compiled vars:  !0 = $arrays, !1 = $result, !2 = $x, !3 = $i, !4 = $y
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                                       $6      !1, ->17
          3    > > FE_FETCH_R                                       ~7      $6, !2, ->17
          4    >   ASSIGN                                                   !3, ~7
    7     5      > FE_RESET_R                                       $9      !0, ->15
          6    > > FE_FETCH_R                                               $9, !4, ->15
    8     7    >   INIT_FCALL                                               'array_merge'
          8        SEND_VAR                                                 !2
          9        INIT_ARRAY                                       ~11     !4
         10        SEND_VAL                                                 ~11
         11        DO_ICALL                                         $12     
         12        ASSIGN_DIM                                               !1, !3
         13        OP_DATA                                                  $12
    7    14      > JMP                                                      ->6
         15    >   FE_FREE                                                  $9
    6    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $6
   11    18      > RETURN                                                   !1
   12    19*     > RETURN                                                   null

End of function direct_product

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.02 ms | 1403 KiB | 19 Q