3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_data = '[ {"name":"Location 1","gigs": {"start":"16:30","end":"21:15","title":"TestTitle1","class":"fri"} }, {"name":"Location 2","gigs": {"start":"15:00","end":"19:00","title":"TestTitle2","class":"fri"} }, {"name":"Location 1","gigs": {"start":"21:00","end":"22:00","title":"TestTitle3","class":"fri"} } ]'; $arr = json_decode($json_data,true); $new_array = array(); foreach ($arr as $key => $value) { if(isset($new_array[$value['name']])) $new_array[$value['name']]['gigs'][] = $value['gigs']; //add already array existing value else{ $new_array[$value['name']]['name'] = $value['name']; $new_array[$value['name']]['gigs'][] = $value['gigs']; //create array } } $new_array = array_values($new_array); //to remove keys echo json_encode($new_array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 32
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 32
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/SO3oP
function name:  (null)
number of ops:  42
compiled vars:  !0 = $json_data, !1 = $arr, !2 = $new_array, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%22name%22%3A%22Location+1%22%2C%22gigs%22%3A+%0A++++++++%7B%22start%22%3A%2216%3A30%22%2C%22end%22%3A%2221%3A15%22%2C%22title%22%3A%22TestTitle1%22%2C%22class%22%3A%22fri%22%7D%0A++++%7D%2C%0A++++%7B%22name%22%3A%22Location+2%22%2C%22gigs%22%3A%0A++++++++%7B%22start%22%3A%2215%3A00%22%2C%22end%22%3A%2219%3A00%22%2C%22title%22%3A%22TestTitle2%22%2C%22class%22%3A%22fri%22%7D%0A++++%7D%2C%0A++++%7B%22name%22%3A%22Location+1%22%2C%22gigs%22%3A%0A++++++++%7B%22start%22%3A%2221%3A00%22%2C%22end%22%3A%2222%3A00%22%2C%22title%22%3A%22TestTitle3%22%2C%22class%22%3A%22fri%22%7D%0A++++%7D%0A%5D'
   14     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !1, $6
   15     6        ASSIGN                                                   !2, <array>
   16     7      > FE_RESET_R                                       $9      !1, ->32
          8    > > FE_FETCH_R                                       ~10     $9, !3, ->32
          9    >   ASSIGN                                                   !4, ~10
   17    10        FETCH_DIM_R                                      ~12     !3, 'name'
         11        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~12
         12      > JMPZ                                                     ~13, ->20
   18    13    >   FETCH_DIM_R                                      ~14     !3, 'name'
         14        FETCH_DIM_R                                      ~18     !3, 'gigs'
         15        FETCH_DIM_W                                      $15     !2, ~14
         16        FETCH_DIM_W                                      $16     $15, 'gigs'
         17        ASSIGN_DIM                                               $16
         18        OP_DATA                                                  ~18
         19      > JMP                                                      ->31
   20    20    >   FETCH_DIM_R                                      ~19     !3, 'name'
         21        FETCH_DIM_R                                      ~22     !3, 'name'
         22        FETCH_DIM_W                                      $20     !2, ~19
         23        ASSIGN_DIM                                               $20, 'name'
         24        OP_DATA                                                  ~22
   21    25        FETCH_DIM_R                                      ~23     !3, 'name'
         26        FETCH_DIM_R                                      ~27     !3, 'gigs'
         27        FETCH_DIM_W                                      $24     !2, ~23
         28        FETCH_DIM_W                                      $25     $24, 'gigs'
         29        ASSIGN_DIM                                               $25
         30        OP_DATA                                                  ~27
   16    31    > > JMP                                                      ->8
         32    >   FE_FREE                                                  $9
   24    33        INIT_FCALL                                               'array_values'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                         $28     
         36        ASSIGN                                                   !2, $28
   25    37        INIT_FCALL                                               'json_encode'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                         $30     
         40        ECHO                                                     $30
         41      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
127.93 ms | 1405 KiB | 19 Q