3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{"id":37,"slug":"red","stock":true,"name":"Red","default":0,"sizes":"38"},{"id":38,"slug":"red","stock":true,"name":"Red","default":0,"sizes":"40"},{"id":34,"slug":"red","stock":true,"name":"Red","default":0,"sizes":"36"},{"id":26,"slug":"green","stock":true,"name":"Green","default":0,"sizes":"48"}]'; $array = json_decode($json,1); $expected = []; foreach($array as $v) { $expected[$v['slug']][] = $v; } $expected_v2 = []; foreach($expected as $k1=>$v1) { array_push($expected_v2,['slug'=>$k1,'name'=>ucfirst($k1),'sizes'=>$v1]); } print_r($expected_v2); echo json_encode($expected_v2); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 30
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 14
filename:       /in/WfbsX
function name:  (null)
number of ops:  39
compiled vars:  !0 = $json, !1 = $array, !2 = $expected, !3 = $v, !4 = $expected_v2, !5 = $v1, !6 = $k1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%5B%7B%22id%22%3A37%2C%22slug%22%3A%22red%22%2C%22stock%22%3Atrue%2C%22name%22%3A%22Red%22%2C%22default%22%3A0%2C%22sizes%22%3A%2238%22%7D%2C%7B%22id%22%3A38%2C%22slug%22%3A%22red%22%2C%22stock%22%3Atrue%2C%22name%22%3A%22Red%22%2C%22default%22%3A0%2C%22sizes%22%3A%2240%22%7D%2C%7B%22id%22%3A34%2C%22slug%22%3A%22red%22%2C%22stock%22%3Atrue%2C%22name%22%3A%22Red%22%2C%22default%22%3A0%2C%22sizes%22%3A%2236%22%7D%2C%7B%22id%22%3A26%2C%22slug%22%3A%22green%22%2C%22stock%22%3Atrue%2C%22name%22%3A%22Green%22%2C%22default%22%3A0%2C%22sizes%22%3A%2248%22%7D%5D'
    3     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !1, $8
    5     6        ASSIGN                                                   !2, <array>
    6     7      > FE_RESET_R                                       $11     !1, ->14
          8    > > FE_FETCH_R                                               $11, !3, ->14
    7     9    >   FETCH_DIM_R                                      ~12     !3, 'slug'
         10        FETCH_DIM_W                                      $13     !2, ~12
         11        ASSIGN_DIM                                               $13
         12        OP_DATA                                                  !3
    6    13      > JMP                                                      ->8
         14    >   FE_FREE                                                  $11
   10    15        ASSIGN                                                   !4, <array>
   11    16      > FE_RESET_R                                       $16     !2, ->30
         17    > > FE_FETCH_R                                       ~17     $16, !5, ->30
         18    >   ASSIGN                                                   !6, ~17
   12    19        INIT_FCALL                                               'array_push'
         20        SEND_REF                                                 !4
         21        INIT_ARRAY                                       ~19     !6, 'slug'
         22        INIT_FCALL                                               'ucfirst'
         23        SEND_VAR                                                 !6
         24        DO_ICALL                                         $20     
         25        ADD_ARRAY_ELEMENT                                ~19     $20, 'name'
         26        ADD_ARRAY_ELEMENT                                ~19     !5, 'sizes'
         27        SEND_VAL                                                 ~19
         28        DO_ICALL                                                 
   11    29      > JMP                                                      ->17
         30    >   FE_FREE                                                  $16
   15    31        INIT_FCALL                                               'print_r'
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                                 
   16    34        INIT_FCALL                                               'json_encode'
         35        SEND_VAR                                                 !4
         36        DO_ICALL                                         $23     
         37        ECHO                                                     $23
   17    38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.78 ms | 1014 KiB | 18 Q