3v4l.org

run code in 300+ PHP versions simultaneously
<?php function multiKeyIt($array, $numKeys) { $multiKeyed = []; foreach($array as $row) { if(!isset($countFields)) { $countFields = count($row); } $arrRef = &$multiKeyed; $theKey = reset($row); for($k = 0; $k < $numKeys; $k++) { if(!isset($arrRef[$theKey])) { $arrRef[$theKey] = array(); } $arrRef = &$arrRef[$theKey]; $theKey = next($row); } //$arrRef = $countFields > $numKeys + 1 ? array_merge($arrRef, array_slice($row,$numKeys)) : implode(', ', array_slice($row,$numKeys)); $arrRef = array_merge($arrRef, array_slice($row,$numKeys)); } return $multiKeyed; } $arr =[ ['key'=>'val_k1', 'val2', 'key1_2'=>'val_d1_2', 'key2_2'=>'val_d2_2'], ['key'=>'val_k1', 'val3', 'key1_3'=>'val_d1_3', 'key2_3'=>'val_d2_3'], ['key'=>'val_kx1', 'val3', 'key1_3'=>'val_d1_x3', 'key2_3'=>'val_d2_3'], ]; echo "<pre>"; $da = multiKeyIt($arr, 1); echo "\n!da(1)=".print_r($da,true); $da = multiKeyIt($arr, 2); echo "\n!da(2)=".print_r($da,true); $da = multiKeyIt($arr, 3); echo "\n!da(3)=".print_r($da,true); $da = multiKeyIt($arr, 4); echo "\n!da(4)=".print_r($da,true); $da = multiKeyIt($arr, 5); echo "\n!da(5)=".print_r($da,true); $da = multiKeyIt($arr, 6); echo "\n!da(6)=".print_r($da,true); echo "</pre>";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5FKd9
function name:  (null)
number of ops:  70
compiled vars:  !0 = $arr, !1 = $da
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, <array>
   30     1        ECHO                                                     '%3Cpre%3E'
   31     2        INIT_FCALL                                               'multikeyit'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 1
          5        DO_FCALL                                      0  $3      
          6        ASSIGN                                                   !1, $3
   32     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $5      
         11        CONCAT                                           ~6      '%0A%21da%281%29%3D', $5
         12        ECHO                                                     ~6
   33    13        INIT_FCALL                                               'multikeyit'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 2
         16        DO_FCALL                                      0  $7      
         17        ASSIGN                                                   !1, $7
   34    18        INIT_FCALL                                               'print_r'
         19        SEND_VAR                                                 !1
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $9      
         22        CONCAT                                           ~10     '%0A%21da%282%29%3D', $9
         23        ECHO                                                     ~10
   36    24        INIT_FCALL                                               'multikeyit'
         25        SEND_VAR                                                 !0
         26        SEND_VAL                                                 3
         27        DO_FCALL                                      0  $11     
         28        ASSIGN                                                   !1, $11
   37    29        INIT_FCALL                                               'print_r'
         30        SEND_VAR                                                 !1
         31        SEND_VAL                                                 <true>
         32        DO_ICALL                                         $13     
         33        CONCAT                                           ~14     '%0A%21da%283%29%3D', $13
         34        ECHO                                                     ~14
   39    35        INIT_FCALL                                               'multikeyit'
         36        SEND_VAR                                                 !0
         37        SEND_VAL                                                 4
         38        DO_FCALL                                      0  $15     
         39        ASSIGN                                                   !1, $15
   40    40        INIT_FCALL                                               'print_r'
         41        SEND_VAR                                                 !1
         42        SEND_VAL                                                 <true>
         43        DO_ICALL                                         $17     
         44        CONCAT                                           ~18     '%0A%21da%284%29%3D', $17
         45        ECHO                                                     ~18
   42    46        INIT_FCALL                                               'multikeyit'
         47        SEND_VAR                                                 !0
         48        SEND_VAL                                                 5
         49        DO_FCALL                                      0  $19     
         50        ASSIGN                                                   !1, $19
   43    51        INIT_FCALL                                               'print_r'
         52        SEND_VAR                                                 !1
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $21     
         55        CONCAT                                           ~22     '%0A%21da%285%29%3D', $21
         56        ECHO                                                     ~22
   45    57        INIT_FCALL                                               'multikeyit'
         58        SEND_VAR                                                 !0
         59        SEND_VAL                                                 6
         60        DO_FCALL                                      0  $23     
         61        ASSIGN                                                   !1, $23
   46    62        INIT_FCALL                                               'print_r'
         63        SEND_VAR                                                 !1
         64        SEND_VAL                                                 <true>
         65        DO_ICALL                                         $25     
         66        CONCAT                                           ~26     '%0A%21da%286%29%3D', $25
         67        ECHO                                                     ~26
   47    68        ECHO                                                     '%3C%2Fpre%3E'
         69      > RETURN                                                   1

Function multikeyit:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 41
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 41
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 17
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 17
Branch analysis from position: 31
Branch analysis from position: 17
Branch analysis from position: 22
Branch analysis from position: 10
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/5FKd9
function name:  multiKeyIt
number of ops:  44
compiled vars:  !0 = $array, !1 = $numKeys, !2 = $multiKeyed, !3 = $row, !4 = $countFields, !5 = $arrRef, !6 = $theKey, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3      > FE_RESET_R                                       $9      !0, ->41
          4    > > FE_FETCH_R                                               $9, !3, ->41
    6     5    >   ISSET_ISEMPTY_CV                                 ~10     !4
          6        BOOL_NOT                                         ~11     ~10
          7      > JMPZ                                                     ~11, ->10
    7     8    >   COUNT                                            ~12     !3
          9        ASSIGN                                                   !4, ~12
    9    10    >   ASSIGN_REF                                               !5, !2
   10    11        INIT_FCALL                                               'reset'
         12        SEND_REF                                                 !3
         13        DO_ICALL                                         $15     
         14        ASSIGN                                                   !6, $15
   11    15        ASSIGN                                                   !7, 0
         16      > JMP                                                      ->29
   12    17    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !5, !6
         18        BOOL_NOT                                         ~19     ~18
         19      > JMPZ                                                     ~19, ->22
   13    20    >   ASSIGN_DIM                                               !5, !6
         21        OP_DATA                                                  <array>
   15    22    >   FETCH_DIM_W                                      $21     !5, !6
         23        ASSIGN_REF                                               !5, $21
   16    24        INIT_FCALL                                               'next'
         25        SEND_REF                                                 !3
         26        DO_ICALL                                         $23     
         27        ASSIGN                                                   !6, $23
   11    28        PRE_INC                                                  !7
         29    >   IS_SMALLER                                               !7, !1
         30      > JMPNZ                                                    ~26, ->17
   19    31    >   INIT_FCALL                                               'array_merge'
         32        SEND_VAR                                                 !5
         33        INIT_FCALL                                               'array_slice'
         34        SEND_VAR                                                 !3
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                         $27     
         37        SEND_VAR                                                 $27
         38        DO_ICALL                                         $28     
         39        ASSIGN                                                   !5, $28
    5    40      > JMP                                                      ->4
         41    >   FE_FREE                                                  $9
   21    42      > RETURN                                                   !2
   22    43*     > RETURN                                                   null

End of function multikeyit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
219.05 ms | 1407 KiB | 29 Q