3v4l.org

run code in 300+ PHP versions simultaneously
<?php $jsonString = '[{"id":1,"category":"Pizza","product":"Large Pizza","complement_type":"Bread","option":"Brown bread"},{"id":2,"category":"Pizza","product":"Small Pizza","complement_type":"Bread","option":"White bread"},{"id":3,"category":"Pizza","product":"Small Pizza","complement_type":"Ingredients","option":"Olives"},{"id":4,"category":"Salads","product":"Green Salad","complement_type":"Extras","option":"Bacon"},{"id":5,"category":"Salads","product":"Cesars Salad","complement_type":"Extras","option":"Lettuce"}]'; $array = json_decode($jsonString); $result = array(); foreach ($array as $row) { if (!isset($result[$row->category])) { $result[$row->category] = array(); } if (!isset($result[$row->category][$row->product])) { $result[$row->category][$row->product] = array(); } $result[$row->category][$row->product][$row->complement_type] = $row->option; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 35
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 35
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
Branch analysis from position: 15
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/euGPC
function name:  (null)
number of ops:  40
compiled vars:  !0 = $jsonString, !1 = $array, !2 = $result, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%7B%22id%22%3A1%2C%22category%22%3A%22Pizza%22%2C%22product%22%3A%22Large+Pizza%22%2C%22complement_type%22%3A%22Bread%22%2C%22option%22%3A%22Brown+bread%22%7D%2C%7B%22id%22%3A2%2C%22category%22%3A%22Pizza%22%2C%22product%22%3A%22Small+Pizza%22%2C%22complement_type%22%3A%22Bread%22%2C%22option%22%3A%22White+bread%22%7D%2C%7B%22id%22%3A3%2C%22category%22%3A%22Pizza%22%2C%22product%22%3A%22Small+Pizza%22%2C%22complement_type%22%3A%22Ingredients%22%2C%22option%22%3A%22Olives%22%7D%2C%7B%22id%22%3A4%2C%22category%22%3A%22Salads%22%2C%22product%22%3A%22Green+Salad%22%2C%22complement_type%22%3A%22Extras%22%2C%22option%22%3A%22Bacon%22%7D%2C%7B%22id%22%3A5%2C%22category%22%3A%22Salads%22%2C%22product%22%3A%22Cesars+Salad%22%2C%22complement_type%22%3A%22Extras%22%2C%22option%22%3A%22Lettuce%22%7D%5D'
    4     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
    6     5        ASSIGN                                                   !2, <array>
    7     6      > FE_RESET_R                                       $8      !1, ->35
          7    > > FE_FETCH_R                                               $8, !3, ->35
    8     8    >   FETCH_OBJ_R                                      ~9      !3, 'category'
          9        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !2, ~9
         10        BOOL_NOT                                         ~11     ~10
         11      > JMPZ                                                     ~11, ->15
    9    12    >   FETCH_OBJ_R                                      ~12     !3, 'category'
         13        ASSIGN_DIM                                               !2, ~12
         14        OP_DATA                                                  <array>
   11    15    >   FETCH_OBJ_R                                      ~14     !3, 'category'
         16        FETCH_OBJ_R                                      ~16     !3, 'product'
         17        FETCH_DIM_IS                                     ~15     !2, ~14
         18        ISSET_ISEMPTY_DIM_OBJ                         0  ~17     ~15, ~16
         19        BOOL_NOT                                         ~18     ~17
         20      > JMPZ                                                     ~18, ->26
   12    21    >   FETCH_OBJ_R                                      ~19     !3, 'category'
         22        FETCH_OBJ_R                                      ~21     !3, 'product'
         23        FETCH_DIM_W                                      $20     !2, ~19
         24        ASSIGN_DIM                                               $20, ~21
         25        OP_DATA                                                  <array>
   14    26    >   FETCH_OBJ_R                                      ~23     !3, 'category'
         27        FETCH_OBJ_R                                      ~25     !3, 'product'
         28        FETCH_OBJ_R                                      ~27     !3, 'complement_type'
         29        FETCH_OBJ_R                                      ~29     !3, 'option'
         30        FETCH_DIM_W                                      $24     !2, ~23
         31        FETCH_DIM_W                                      $26     $24, ~25
         32        ASSIGN_DIM                                               $26, ~27
         33        OP_DATA                                                  ~29
    7    34      > JMP                                                      ->7
         35    >   FE_FREE                                                  $8
   17    36        INIT_FCALL                                               'print_r'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                                 
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.5 ms | 1011 KiB | 15 Q