3v4l.org

run code in 300+ PHP versions simultaneously
<?php $jsonData = '[{ "brand": {"id": "fe877b45-8620-453a-8805-63f0cbd80752", "name": "No Brand", "slug": "no-brand", "description": "null"}, "options": [{"id": "324af955-1aa9-42ea-be6e-bb4e5623a97a", "parent_id": "null", "name": "Need Insurance?"}, {"id": "73298c18-4ccc-4138-afa5-71d3d00dff9b", "parent_id": "null", "name": "Color", "slug": "color"}], "rating": [], "tags": [{"id": "8a31ee4c-3302-4357-9686-bd4308bbf39f", "name": "options", "slug": "options", "photo": "null"}], "variations": [{"id": "3bf5aeb9-9da2-4fb1-a3d2-f89eb75839c3", "parent_id": "null", "name": "Ram", "slug": "ram", "photo": "null"}, {"id": "e5c70766-a558-4539-b41f-77f72c819a7c", "parent_id": "null", "name": "cpu", "slug": "cpu", "photo": "null"}, {"id": "e63ac831-f595-4889-83d2-a5be65734758", "parent_id": "null", "name": "Monitor", "slug": "monitor"} ] }, { "brand": {"id": "fe877b45-8620-453a-8805-63f0cbd80752", "name": "No Brand", "slug": "no-brand", "description": null}, "options": [{"id": "522da418-eb3f-43e9-9392-63c941842a52", "parent_id": null, "name": "Color", "slug": "color-3"}], "rating": [], "tags": [], "variations": [{"id": "8e9a26c5-2ee4-4d86-9244-a10596d67fea", "parent_id": null, "name": "Cpu", "slug": "cpu-3", "photo": null}] } ] '; $jsonDataArr =json_decode($jsonData); $data = array(); foreach($jsonDataArr as $key => $items){ foreach($items as $innerKey => $eachItem){ if(!isset($data[$innerKey])){ $data[$innerKey] = array(); if(is_array($eachItem)){ foreach($eachItem as $each) if(!empty($each)) $data[$innerKey][] = (array) $each; }else{ if(!empty($eachItem)) $data[$innerKey][] = (array) $eachItem; } }else{ if(is_array($eachItem)){ foreach($eachItem as $each) if(!empty($each)) $data[$innerKey][] = (array) $each; }else{ if(!empty($eachItem)) $data[$innerKey][] = (array) $eachItem; } } } } foreach($data as $key => $val){ foreach($val as $l => $item){ $index = trim(strtolower($item['name'])); $data[$key][$index] = $item; unset($data[$key][$l]); } } foreach($data as $key => $val){ $data[$key]=array_values($val); } print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 63
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 63
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 61
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 61
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 39
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 31
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 29
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 29
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 28
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 29
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 38
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 38
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 53
Branch analysis from position: 41
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 51
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 51
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 50
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 51
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 60
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 60
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 61
Branch analysis from position: 63
2 jumps found. (Code = 77) Position 1 = 65, Position 2 = 86
Branch analysis from position: 65
2 jumps found. (Code = 78) Position 1 = 66, Position 2 = 86
Branch analysis from position: 66
2 jumps found. (Code = 77) Position 1 = 68, Position 2 = 84
Branch analysis from position: 68
2 jumps found. (Code = 78) Position 1 = 69, Position 2 = 84
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
Branch analysis from position: 84
Branch analysis from position: 86
2 jumps found. (Code = 77) Position 1 = 88, Position 2 = 96
Branch analysis from position: 88
2 jumps found. (Code = 78) Position 1 = 89, Position 2 = 96
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
Branch analysis from position: 96
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 96
Branch analysis from position: 86
Branch analysis from position: 63
filename:       /in/0u1pF
function name:  (null)
number of ops:  101
compiled vars:  !0 = $jsonData, !1 = $jsonDataArr, !2 = $data, !3 = $items, !4 = $key, !5 = $eachItem, !6 = $innerKey, !7 = $each, !8 = $val, !9 = $item, !10 = $l, !11 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%7B%0A%09%22brand%22%3A+%7B%22id%22%3A+%22fe877b45-8620-453a-8805-63f0cbd80752%22%2C+%22name%22%3A+%22No+Brand%22%2C+%22slug%22%3A+%22no-brand%22%2C+%22description%22%3A+%22null%22%7D%2C%0A%09%22options%22%3A+%5B%7B%22id%22%3A+%22324af955-1aa9-42ea-be6e-bb4e5623a97a%22%2C+%22parent_id%22%3A+%22null%22%2C+%22name%22%3A+%22Need+Insurance%3F%22%7D%2C%0A%09%7B%22id%22%3A+%2273298c18-4ccc-4138-afa5-71d3d00dff9b%22%2C+%22parent_id%22%3A+%22null%22%2C+%22name%22%3A+%22Color%22%2C+%22slug%22%3A+%22color%22%7D%5D%2C%0A%09%22rating%22%3A+%5B%5D%2C%0A%09%22tags%22%3A+%5B%7B%22id%22%3A+%228a31ee4c-3302-4357-9686-bd4308bbf39f%22%2C+%22name%22%3A+%22options%22%2C+%22slug%22%3A+%22options%22%2C+%22photo%22%3A+%22null%22%7D%5D%2C%0A%09%22variations%22%3A+%5B%7B%22id%22%3A+%223bf5aeb9-9da2-4fb1-a3d2-f89eb75839c3%22%2C+%22parent_id%22%3A+%22null%22%2C+%22name%22%3A+%22Ram%22%2C+%22slug%22%3A+%22ram%22%2C+%22photo%22%3A+%22null%22%7D%2C%0A%09%7B%22id%22%3A+%22e5c70766-a558-4539-b41f-77f72c819a7c%22%2C+%22parent_id%22%3A+%22null%22%2C+%22name%22%3A+%22cpu%22%2C+%22slug%22%3A+%22cpu%22%2C+%22photo%22%3A+%22null%22%7D%2C%0A%09%7B%22id%22%3A+%22e63ac831-f595-4889-83d2-a5be65734758%22%2C+%22parent_id%22%3A+%22null%22%2C+%22name%22%3A+%22Monitor%22%2C+%22slug%22%3A+%22monitor%22%7D%0A%09%5D%0A%09%7D%2C%0A%09%7B%0A%09%22brand%22%3A+%7B%22id%22%3A+%22fe877b45-8620-453a-8805-63f0cbd80752%22%2C+%22name%22%3A+%22No+Brand%22%2C+%22slug%22%3A+%22no-brand%22%2C+%22description%22%3A+null%7D%2C%0A%09%22options%22%3A+%5B%7B%22id%22%3A+%22522da418-eb3f-43e9-9392-63c941842a52%22%2C+%22parent_id%22%3A+null%2C+%22name%22%3A+%22Color%22%2C+%22slug%22%3A+%22color-3%22%7D%5D%2C%0A%09%22rating%22%3A+%5B%5D%2C%0A%09%22tags%22%3A+%5B%5D%2C%0A%09%22variations%22%3A+%5B%7B%22id%22%3A+%228e9a26c5-2ee4-4d86-9244-a10596d67fea%22%2C+%22parent_id%22%3A+null%2C+%22name%22%3A+%22Cpu%22%2C+%22slug%22%3A+%22cpu-3%22%2C+%22photo%22%3A+null%7D%5D%0A%09%7D%0A%09%5D%0A%09'
   25     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $13     
          4        ASSIGN                                                   !1, $13
   26     5        ASSIGN                                                   !2, <array>
   28     6      > FE_RESET_R                                       $16     !1, ->63
          7    > > FE_FETCH_R                                       ~17     $16, !3, ->63
          8    >   ASSIGN                                                   !4, ~17
   30     9      > FE_RESET_R                                       $19     !3, ->61
         10    > > FE_FETCH_R                                       ~20     $19, !5, ->61
         11    >   ASSIGN                                                   !6, ~20
   31    12        ISSET_ISEMPTY_DIM_OBJ                         0  ~22     !2, !6
         13        BOOL_NOT                                         ~23     ~22
         14      > JMPZ                                                     ~23, ->39
   32    15    >   ASSIGN_DIM                                               !2, !6
         16        OP_DATA                                                  <array>
   33    17        TYPE_CHECK                                  128          !5
         18      > JMPZ                                                     ~25, ->31
   35    19    > > FE_RESET_R                                       $26     !5, ->29
         20    > > FE_FETCH_R                                               $26, !7, ->29
   36    21    >   ISSET_ISEMPTY_CV                                 ~27     !7
         22        BOOL_NOT                                         ~28     ~27
         23      > JMPZ                                                     ~28, ->28
   37    24    >   CAST                                          7  ~31     !7
         25        FETCH_DIM_W                                      $29     !2, !6
         26        ASSIGN_DIM                                               $29
         27        OP_DATA                                                  ~31
   35    28    > > JMP                                                      ->20
         29    >   FE_FREE                                                  $26
   33    30      > JMP                                                      ->38
   41    31    >   ISSET_ISEMPTY_CV                                 ~32     !5
         32        BOOL_NOT                                         ~33     ~32
         33      > JMPZ                                                     ~33, ->38
   42    34    >   CAST                                          7  ~36     !5
         35        FETCH_DIM_W                                      $34     !2, !6
         36        ASSIGN_DIM                                               $34
         37        OP_DATA                                                  ~36
   31    38    > > JMP                                                      ->60
   46    39    >   TYPE_CHECK                                  128          !5
         40      > JMPZ                                                     ~37, ->53
   47    41    > > FE_RESET_R                                       $38     !5, ->51
         42    > > FE_FETCH_R                                               $38, !7, ->51
   48    43    >   ISSET_ISEMPTY_CV                                 ~39     !7
         44        BOOL_NOT                                         ~40     ~39
         45      > JMPZ                                                     ~40, ->50
   49    46    >   CAST                                          7  ~43     !7
         47        FETCH_DIM_W                                      $41     !2, !6
         48        ASSIGN_DIM                                               $41
         49        OP_DATA                                                  ~43
   47    50    > > JMP                                                      ->42
         51    >   FE_FREE                                                  $38
   46    52      > JMP                                                      ->60
   52    53    >   ISSET_ISEMPTY_CV                                 ~44     !5
         54        BOOL_NOT                                         ~45     ~44
         55      > JMPZ                                                     ~45, ->60
   53    56    >   CAST                                          7  ~48     !5
         57        FETCH_DIM_W                                      $46     !2, !6
         58        ASSIGN_DIM                                               $46
         59        OP_DATA                                                  ~48
   30    60    > > JMP                                                      ->10
         61    >   FE_FREE                                                  $19
   28    62      > JMP                                                      ->7
         63    >   FE_FREE                                                  $16
   60    64      > FE_RESET_R                                       $49     !2, ->86
         65    > > FE_FETCH_R                                       ~50     $49, !8, ->86
         66    >   ASSIGN                                                   !4, ~50
   62    67      > FE_RESET_R                                       $52     !8, ->84
         68    > > FE_FETCH_R                                       ~53     $52, !9, ->84
         69    >   ASSIGN                                                   !10, ~53
   63    70        INIT_FCALL                                               'trim'
         71        INIT_FCALL                                               'strtolower'
         72        FETCH_DIM_R                                      ~55     !9, 'name'
         73        SEND_VAL                                                 ~55
         74        DO_ICALL                                         $56     
         75        SEND_VAR                                                 $56
         76        DO_ICALL                                         $57     
         77        ASSIGN                                                   !11, $57
   64    78        FETCH_DIM_W                                      $59     !2, !4
         79        ASSIGN_DIM                                               $59, !11
         80        OP_DATA                                                  !9
   65    81        FETCH_DIM_UNSET                                  $61     !2, !4
         82        UNSET_DIM                                                $61, !10
   62    83      > JMP                                                      ->68
         84    >   FE_FREE                                                  $52
   60    85      > JMP                                                      ->65
         86    >   FE_FREE                                                  $49
   70    87      > FE_RESET_R                                       $62     !2, ->96
         88    > > FE_FETCH_R                                       ~63     $62, !8, ->96
         89    >   ASSIGN                                                   !4, ~63
   71    90        INIT_FCALL                                               'array_values'
         91        SEND_VAR                                                 !8
         92        DO_ICALL                                         $66     
         93        ASSIGN_DIM                                               !2, !4
         94        OP_DATA                                                  $66
   70    95      > JMP                                                      ->88
         96    >   FE_FREE                                                  $62
   74    97        INIT_FCALL                                               'print_r'
         98        SEND_VAR                                                 !2
         99        DO_ICALL                                                 
        100      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.82 ms | 1017 KiB | 18 Q