3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decartProduct($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 $result; } function createAssociation() { $args = func_get_args(); if(!count($args)) { return []; } $result = array_shift($args); while($array=array_shift($args)) { $result=decartProduct($result, $array); } $result = array_filter($result, function($tuple) { return array_unique($tuple)==$tuple; }); return $result; } $i[0] = ['a', 'b', 'c']; $i[1] = ['d', 'e']; $i[2] = ['a', 'b', 'c']; $i[3] = ['d', 'e']; $i[4] = ['f', 'g', 'h']; $result = call_user_func_array('createAssociation', $i); var_dump($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vrmGm
function name:  (null)
number of ops:  19
compiled vars:  !0 = $i, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN_DIM                                               !0, 0
          1        OP_DATA                                                  <array>
   35     2        ASSIGN_DIM                                               !0, 1
          3        OP_DATA                                                  <array>
   36     4        ASSIGN_DIM                                               !0, 2
          5        OP_DATA                                                  <array>
   37     6        ASSIGN_DIM                                               !0, 3
          7        OP_DATA                                                  <array>
   38     8        ASSIGN_DIM                                               !0, 4
          9        OP_DATA                                                  <array>
   40    10        INIT_FCALL                                               'createassociation'
         11        SEND_ARRAY                                               !0
         12        CHECK_UNDEF_ARGS                                         
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !1, $7
   42    15        INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function decartproduct:
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/vrmGm
function name:  decartProduct
number of ops:  27
compiled vars:  !0 = $one, !1 = $two, !2 = $result, !3 = $i, !4 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->22
    7     5    >   ASSIGN                                                   !4, 0
          6      > JMP                                                      ->18
    9     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
    7    17        PRE_INC                                                  !4
         18    >   COUNT                                            ~15     !1
         19        IS_SMALLER                                               !4, ~15
         20      > JMPNZ                                                    ~16, ->7
    5    21    >   PRE_INC                                                  !3
         22    >   COUNT                                            ~18     !0
         23        IS_SMALLER                                               !3, ~18
         24      > JMPNZ                                                    ~19, ->5
   12    25    > > RETURN                                                   !2
   13    26*     > RETURN                                                   null

End of function decartproduct

Function createassociation:
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/vrmGm
function name:  createAssociation
number of ops:  29
compiled vars:  !0 = $args, !1 = $result, !2 = $array
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                                               'decartproduct'
         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    >   INIT_FCALL                                               'array_filter'
         22        SEND_VAR                                                 !1
         23        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FvrmGm%3A27%240'
   30    24        SEND_VAL                                                 ~13
         25        DO_ICALL                                         $14     
   27    26        ASSIGN                                                   !1, $14
   31    27      > RETURN                                                   !1
   32    28*     > RETURN                                                   null

End of function createassociation

Function %00%7Bclosure%7D%2Fin%2FvrmGm%3A27%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vrmGm
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $tuple
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'array_unique'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        IS_EQUAL                                         ~2      !0, $1
          5      > RETURN                                                   ~2
   30     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FvrmGm%3A27%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.91 ms | 1407 KiB | 25 Q