3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ ['item1' => 'a', 'item2' => 'c', 'item3' => 'd2', 'item4' => 'f'], ['item1' => 'a', 'item2' => 'c', 'item3' => 'd2', 'item4' => 'g'], ['item1' => 'a', 'item2' => 'd', 'item3' => 'd3', 'item4' => 'h'], ['item1' => 'a', 'item2' => 'd', 'item3' => 'e', 'item4' => 'i'], ['item1' => 'b', 'item2' => 'c', 'item3' => 'e', 'item4' => 'j'], ['item1' => 'b', 'item2' => 'c', 'item3' => 'e', 'item4' => 'k'] ]; $result = []; foreach ($items as $row) { $k1 = $row['item1']; $k2 = $row['item1'] . '_' . $row['item2']; $k3 = $row['item1'] . '_' . $row['item2'] . '_' . $row['item3']; if (!isset($ref3[$k3])) { $ref3[$k3] = [$row['item3'], [$row['item4']]]; if (!isset($ref2[$k2])) { $ref2[$k2] = [$row['item2'], &$ref3[$k3]]; if (!isset($ref1[$k1])) { $ref1[$k1] = [$row['item1'], &$ref2[$k2]]; $result[] = &$ref1[$k1]; } else { $ref1[$k1][] = &$ref2[$k2]; } } else { $ref2[$k2][1][] = &$ref3[$k3]; } } else { $ref3[$k3][1][] = $row['item4']; } } echo json_encode($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 71
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 71
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 65
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 58
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 52
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
filename:       /in/PUlik
function name:  (null)
number of ops:  77
compiled vars:  !0 = $items, !1 = $result, !2 = $row, !3 = $k1, !4 = $k2, !5 = $k3, !6 = $ref3, !7 = $ref2, !8 = $ref1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   13     2      > FE_RESET_R                                       $11     !0, ->71
          3    > > FE_FETCH_R                                               $11, !2, ->71
   14     4    >   FETCH_DIM_R                                      ~12     !2, 'item1'
          5        ASSIGN                                                   !3, ~12
   15     6        FETCH_DIM_R                                      ~14     !2, 'item1'
          7        CONCAT                                           ~15     ~14, '_'
          8        FETCH_DIM_R                                      ~16     !2, 'item2'
          9        CONCAT                                           ~17     ~15, ~16
         10        ASSIGN                                                   !4, ~17
   16    11        FETCH_DIM_R                                      ~19     !2, 'item1'
         12        CONCAT                                           ~20     ~19, '_'
         13        FETCH_DIM_R                                      ~21     !2, 'item2'
         14        CONCAT                                           ~22     ~20, ~21
         15        CONCAT                                           ~23     ~22, '_'
         16        FETCH_DIM_R                                      ~24     !2, 'item3'
         17        CONCAT                                           ~25     ~23, ~24
         18        ASSIGN                                                   !5, ~25
   17    19        ISSET_ISEMPTY_DIM_OBJ                         0  ~27     !6, !5
         20        BOOL_NOT                                         ~28     ~27
         21      > JMPZ                                                     ~28, ->65
   18    22    >   FETCH_DIM_R                                      ~30     !2, 'item3'
         23        INIT_ARRAY                                       ~31     ~30
         24        FETCH_DIM_R                                      ~32     !2, 'item4'
         25        INIT_ARRAY                                       ~33     ~32
         26        ADD_ARRAY_ELEMENT                                ~31     ~33
         27        ASSIGN_DIM                                               !6, !5
         28        OP_DATA                                                  ~31
   19    29        ISSET_ISEMPTY_DIM_OBJ                         0  ~34     !7, !4
         30        BOOL_NOT                                         ~35     ~34
         31      > JMPZ                                                     ~35, ->58
   20    32    >   FETCH_DIM_R                                      ~37     !2, 'item2'
         33        INIT_ARRAY                                       ~38     ~37
         34        FETCH_DIM_W                                      $39     !6, !5
         35        ADD_ARRAY_ELEMENT                                ~38     $39
         36        ASSIGN_DIM                                               !7, !4
         37        OP_DATA                                                  ~38
   21    38        ISSET_ISEMPTY_DIM_OBJ                         0  ~40     !8, !3
         39        BOOL_NOT                                         ~41     ~40
         40      > JMPZ                                                     ~41, ->52
   22    41    >   FETCH_DIM_R                                      ~43     !2, 'item1'
         42        INIT_ARRAY                                       ~44     ~43
         43        FETCH_DIM_W                                      $45     !7, !4
         44        ADD_ARRAY_ELEMENT                                ~44     $45
         45        ASSIGN_DIM                                               !8, !3
         46        OP_DATA                                                  ~44
   23    47        FETCH_DIM_W                                      $47     !8, !3
         48        MAKE_REF                                         $48     $47
         49        FETCH_DIM_W                                      $46     !1
         50        ASSIGN_REF                                               $46, $48
   21    51      > JMP                                                      ->57
   25    52    >   FETCH_DIM_W                                      $52     !7, !4
         53        MAKE_REF                                         $53     $52
         54        FETCH_DIM_W                                      $50     !8, !3
         55        FETCH_DIM_W                                      $51     $50
         56        ASSIGN_REF                                               $51, $53
   19    57    > > JMP                                                      ->64
   28    58    >   FETCH_DIM_W                                      $58     !6, !5
         59        MAKE_REF                                         $59     $58
         60        FETCH_DIM_W                                      $55     !7, !4
         61        FETCH_DIM_W                                      $56     $55, 1
         62        FETCH_DIM_W                                      $57     $56
         63        ASSIGN_REF                                               $57, $59
   17    64    > > JMP                                                      ->70
   31    65    >   FETCH_DIM_R                                      ~64     !2, 'item4'
         66        FETCH_DIM_W                                      $61     !6, !5
         67        FETCH_DIM_W                                      $62     $61, 1
         68        ASSIGN_DIM                                               $62
         69        OP_DATA                                                  ~64
   13    70    > > JMP                                                      ->3
         71    >   FE_FREE                                                  $11
   34    72        INIT_FCALL                                               'json_encode'
         73        SEND_VAR                                                 !1
         74        DO_ICALL                                         $65     
         75        ECHO                                                     $65
         76      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
136.92 ms | 1002 KiB | 14 Q