3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['cat' => 'guest', 'name' => 'name_one', 'y' => '2016', 'q' => '2', 'st' => 1], ['cat' => 'guest', 'name' => 'name_one', 'y' => '2017', 'q' => '3', 'st' => 2], ['cat' => 'guest', 'name' => 'name_two', 'y' => '2017', 'q' => '1', 'st' => 1], ['cat' => 'guest', 'name' => 'name_two', 'y' => '2017', 'q' => '2', 'st' => 2], ]; $data = []; foreach ($rows as $row) { $link = &$data; foreach (['cat', 'name', 'y'] as $field) { if (!isset($link[$field])) $link[$field] = []; if (!isset($link[$field][$row[$field]])) $link[$field][$row[$field]] = []; $link = &$link[$field][$row[$field]]; } $link[] = ['q' => $row['q'], 'st' => $row['st']]; unset($link); } echo json_encode($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 21
Branch analysis from position: 12
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/dUBK4
function name:  (null)
number of ops:  41
compiled vars:  !0 = $rows, !1 = $data, !2 = $row, !3 = $link, !4 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $7      !0, ->35
          3    > > FE_FETCH_R                                               $7, !2, ->35
   13     4    >   ASSIGN_REF                                               !3, !1
   14     5      > FE_RESET_R                                       $9      <array>, ->26
          6    > > FE_FETCH_R                                               $9, !4, ->26
   15     7    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !3, !4
          8        BOOL_NOT                                         ~11     ~10
          9      > JMPZ                                                     ~11, ->12
         10    >   ASSIGN_DIM                                               !3, !4
         11        OP_DATA                                                  <array>
   16    12    >   FETCH_DIM_R                                      ~14     !2, !4
         13        FETCH_DIM_IS                                     ~13     !3, !4
         14        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     ~13, ~14
         15        BOOL_NOT                                         ~16     ~15
         16      > JMPZ                                                     ~16, ->21
         17    >   FETCH_DIM_R                                      ~18     !2, !4
         18        FETCH_DIM_W                                      $17     !3, !4
         19        ASSIGN_DIM                                               $17, ~18
         20        OP_DATA                                                  <array>
   17    21    >   FETCH_DIM_R                                      ~21     !2, !4
         22        FETCH_DIM_W                                      $20     !3, !4
         23        FETCH_DIM_W                                      $22     $20, ~21
         24        ASSIGN_REF                                               !3, $22
   14    25      > JMP                                                      ->6
         26    >   FE_FREE                                                  $9
   19    27        FETCH_DIM_R                                      ~25     !2, 'q'
         28        INIT_ARRAY                                       ~26     ~25, 'q'
         29        FETCH_DIM_R                                      ~27     !2, 'st'
         30        ADD_ARRAY_ELEMENT                                ~26     ~27, 'st'
         31        ASSIGN_DIM                                               !3
         32        OP_DATA                                                  ~26
   20    33        UNSET_CV                                                 !3
   12    34      > JMP                                                      ->3
         35    >   FE_FREE                                                  $7
   23    36        INIT_FCALL                                               'json_encode'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $28     
         39        ECHO                                                     $28
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
192.89 ms | 1400 KiB | 15 Q