3v4l.org

run code in 300+ PHP versions simultaneously
<?php $templateData = [ 'h', 1, 2, 3, 'c-1-3', 3, 5, 'c-2-3', 3, 'c-3-3', 'f', 2 ]; $result = []; foreach ($templateData as $v) { if (!is_int($v)) { if (isset($k2) && empty($ref2[$k2])) { $ref2[$k2][] = 0; // set default 0 if previous group received no values } $k2 = $v; // cache the level 2 value $k1 = strtok($v, '-'); // cache the level 1 value if (!isset($ref1[$k1])) { $ref1[$k1] = []; $result[] =& $ref1[$k1]; // push level 1 reference into result array } if (!isset($ref2[$k2])) { $ref2[$k2] = []; $ref1[$k1][] =& $ref2[$k2]; // push level 2 reference into level 1 reference } } elseif (isset($k2)) { $ref2[$k2][] = $v; // push integer into level 2 reference } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 47
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 47
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 41
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 30
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 40
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 40
Branch analysis from position: 30
Branch analysis from position: 15
Branch analysis from position: 11
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 46
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/Pg5Ce
function name:  (null)
number of ops:  52
compiled vars:  !0 = $templateData, !1 = $result, !2 = $v, !3 = $k2, !4 = $ref2, !5 = $k1, !6 = $ref1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   18     1        ASSIGN                                                   !1, <array>
   19     2      > FE_RESET_R                                       $9      !0, ->47
          3    > > FE_FETCH_R                                               $9, !2, ->47
   20     4    >   TYPE_CHECK                                   16  ~10     !2
          5        BOOL_NOT                                         ~11     ~10
          6      > JMPZ                                                     ~11, ->41
   21     7    >   ISSET_ISEMPTY_CV                                 ~12     !3
          8      > JMPZ_EX                                          ~12     ~12, ->11
          9    >   ISSET_ISEMPTY_DIM_OBJ                         1  ~13     !4, !3
         10        BOOL                                             ~12     ~13
         11    > > JMPZ                                                     ~12, ->15
   22    12    >   FETCH_DIM_W                                      $14     !4, !3
         13        ASSIGN_DIM                                               $14
         14        OP_DATA                                                  0
   24    15    >   ASSIGN                                                   !3, !2
   25    16        INIT_FCALL                                               'strtok'
         17        SEND_VAR                                                 !2
         18        SEND_VAL                                                 '-'
         19        DO_ICALL                                         $17     
         20        ASSIGN                                                   !5, $17
   26    21        ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !6, !5
         22        BOOL_NOT                                         ~20     ~19
         23      > JMPZ                                                     ~20, ->30
   27    24    >   ASSIGN_DIM                                               !6, !5
         25        OP_DATA                                                  <array>
   28    26        FETCH_DIM_W                                      $23     !6, !5
         27        MAKE_REF                                         $24     $23
         28        FETCH_DIM_W                                      $22     !1
         29        ASSIGN_REF                                               $22, $24
   30    30    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~26     !4, !3
         31        BOOL_NOT                                         ~27     ~26
         32      > JMPZ                                                     ~27, ->40
   31    33    >   ASSIGN_DIM                                               !4, !3
         34        OP_DATA                                                  <array>
   32    35        FETCH_DIM_W                                      $31     !4, !3
         36        MAKE_REF                                         $32     $31
         37        FETCH_DIM_W                                      $29     !6, !5
         38        FETCH_DIM_W                                      $30     $29
         39        ASSIGN_REF                                               $30, $32
   20    40    > > JMP                                                      ->46
   34    41    >   ISSET_ISEMPTY_CV                                         !3
         42      > JMPZ                                                     ~34, ->46
   35    43    >   FETCH_DIM_W                                      $35     !4, !3
         44        ASSIGN_DIM                                               $35
         45        OP_DATA                                                  !2
   19    46    > > JMP                                                      ->3
         47    >   FE_FREE                                                  $9
   38    48        INIT_FCALL                                               'var_export'
         49        SEND_VAR                                                 !1
         50        DO_ICALL                                                 
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.43 ms | 1016 KiB | 15 Q