3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[{"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-03-27"}, {"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2005-04-13"}, {"REG":"SK", "RES":"PAN1", "WELL":"P1-TG", "TIME":"2006-06-07"}, {"REG":"SK", "RES":"PAN2", "WELL":"P2-TG", "TIME":"2009-01-18"}, {"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2009-03-01"}, {"REG":"SK", "RES":"PAN3", "WELL":"P3-TG", "TIME":"2010-03-14"}]'; foreach (json_decode($json, true) as $row) { $composite_key = implode('-', array_slice($row, 0, 3)); if (!isset($result[$composite_key])) { $row['TIME'] = [$row['TIME']]; $result[$composite_key] = $row; } else { $result[$composite_key]['TIME'][] = $row['TIME']; } } echo json_encode(array_values($result), JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 33
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/oiLfC
function name:  (null)
number of ops:  43
compiled vars:  !0 = $json, !1 = $row, !2 = $composite_key, !3 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%5B%7B%22REG%22%3A%22SK%22%2C+%22RES%22%3A%22PAN1%22%2C+%22WELL%22%3A%22P1-TG%22%2C+%22TIME%22%3A%222005-03-27%22%7D%2C%0A%7B%22REG%22%3A%22SK%22%2C+%22RES%22%3A%22PAN1%22%2C+%22WELL%22%3A%22P1-TG%22%2C+%22TIME%22%3A%222005-04-13%22%7D%2C%0A%7B%22REG%22%3A%22SK%22%2C+%22RES%22%3A%22PAN1%22%2C+%22WELL%22%3A%22P1-TG%22%2C+%22TIME%22%3A%222006-06-07%22%7D%2C%0A%7B%22REG%22%3A%22SK%22%2C+%22RES%22%3A%22PAN2%22%2C+%22WELL%22%3A%22P2-TG%22%2C+%22TIME%22%3A%222009-01-18%22%7D%2C%0A%7B%22REG%22%3A%22SK%22%2C+%22RES%22%3A%22PAN3%22%2C+%22WELL%22%3A%22P3-TG%22%2C+%22TIME%22%3A%222009-03-01%22%7D%2C%0A%7B%22REG%22%3A%22SK%22%2C+%22RES%22%3A%22PAN3%22%2C+%22WELL%22%3A%22P3-TG%22%2C+%22TIME%22%3A%222010-03-14%22%7D%5D'
    9     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $5      
          5      > FE_RESET_R                                       $6      $5, ->33
          6    > > FE_FETCH_R                                               $6, !1, ->33
   10     7    >   INIT_FCALL                                               'implode'
          8        SEND_VAL                                                 '-'
          9        INIT_FCALL                                               'array_slice'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 0
         12        SEND_VAL                                                 3
         13        DO_ICALL                                         $7      
         14        SEND_VAR                                                 $7
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   11    17        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !3, !2
         18        BOOL_NOT                                         ~11     ~10
         19      > JMPZ                                                     ~11, ->27
   12    20    >   FETCH_DIM_R                                      ~13     !1, 'TIME'
         21        INIT_ARRAY                                       ~14     ~13
         22        ASSIGN_DIM                                               !1, 'TIME'
         23        OP_DATA                                                  ~14
   13    24        ASSIGN_DIM                                               !3, !2
         25        OP_DATA                                                  !1
         26      > JMP                                                      ->32
   15    27    >   FETCH_DIM_R                                      ~19     !1, 'TIME'
         28        FETCH_DIM_W                                      $16     !3, !2
         29        FETCH_DIM_W                                      $17     $16, 'TIME'
         30        ASSIGN_DIM                                               $17
         31        OP_DATA                                                  ~19
    9    32    > > JMP                                                      ->6
         33    >   FE_FREE                                                  $6
   18    34        INIT_FCALL                                               'json_encode'
         35        INIT_FCALL                                               'array_values'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                         $20     
         38        SEND_VAR                                                 $20
         39        SEND_VAL                                                 128
         40        DO_ICALL                                         $21     
         41        ECHO                                                     $21
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.69 ms | 1400 KiB | 23 Q