3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = '[{ "thn": "2017", "jumlah": "30" }, { "thn": "2018", "jumlah": "80" }, { "thn": "2018", "jumlah": "64" }, { "thn": "2018", "jumlah": "5" }, { "thn": "2018", "jumlah": "1" }, { "thn": "2018", "jumlah": "1" }, { "thn": "2018", "jumlah": "4" }, { "thn": "2018", "jumlah": "5" }, { "thn": "2018", "jumlah": "198" }, { "thn": "2018", "jumlah": "2" }, { "thn": "2018", "jumlah": "202" }, { "thn": "2019", "jumlah": "31" }, { "thn": "2019", "jumlah": "1" }]'; $array = json_decode($json,true); $finalArray = array(); foreach($array as $arr){ $finalArray[$arr['thn']]['jumlah'] = (isset($finalArray[$arr['thn']]['jumlah']) ? $finalArray[$arr['thn']]['jumlah'] + $arr['jumlah']: $arr['jumlah']); $finalArray[$arr['thn']]['thn'] = $arr['thn']; } $finalArray = array_values($finalArray); echo json_encode($finalArray);
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 = 14, Position 2 = 21
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 21
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/hZWUh
function name:  (null)
number of ops:  42
compiled vars:  !0 = $json, !1 = $array, !2 = $finalArray, !3 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%5B%7B%0A%09%22thn%22%3A+%222017%22%2C%0A%09%22jumlah%22%3A+%2230%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%2280%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%2264%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%225%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%221%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%221%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%224%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%225%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%22198%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%222%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222018%22%2C%0A%09%22jumlah%22%3A+%22202%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222019%22%2C%0A%09%22jumlah%22%3A+%2231%22%0A%7D%2C+%7B%0A%09%22thn%22%3A+%222019%22%2C%0A%09%22jumlah%22%3A+%221%22%0A%7D%5D'
   44     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $5      
          5        ASSIGN                                                       !1, $5
   46     6        ASSIGN                                                       !2, <array>
   48     7      > FE_RESET_R                                           $8      !1, ->32
          8    > > FE_FETCH_R                                                   $8, !3, ->32
   50     9    >   FETCH_DIM_R                                          ~9      !3, 'thn'
         10        FETCH_DIM_R                                          ~12     !3, 'thn'
         11        FETCH_DIM_IS                                         ~13     !2, ~12
         12        ISSET_ISEMPTY_DIM_OBJ                             0          ~13, 'jumlah'
         13      > JMPZ                                                         ~14, ->21
         14    >   FETCH_DIM_R                                          ~15     !3, 'thn'
         15        FETCH_DIM_R                                          ~16     !2, ~15
         16        FETCH_DIM_R                                          ~17     ~16, 'jumlah'
         17        FETCH_DIM_R                                          ~18     !3, 'jumlah'
         18        ADD                                                  ~19     ~17, ~18
         19        QM_ASSIGN                                            ~20     ~19
         20      > JMP                                                          ->23
         21    >   FETCH_DIM_R                                          ~21     !3, 'jumlah'
         22        QM_ASSIGN                                            ~20     ~21
         23    >   FETCH_DIM_W                                          $10     !2, ~9
         24        ASSIGN_DIM                                                   $10, 'jumlah'
         25        OP_DATA                                                      ~20
   51    26        FETCH_DIM_R                                          ~22     !3, 'thn'
         27        FETCH_DIM_R                                          ~25     !3, 'thn'
         28        FETCH_DIM_W                                          $23     !2, ~22
         29        ASSIGN_DIM                                                   $23, 'thn'
         30        OP_DATA                                                      ~25
   48    31      > JMP                                                          ->8
         32    >   FE_FREE                                                      $8
   53    33        INIT_FCALL                                                   'array_values'
         34        SEND_VAR                                                     !2
         35        DO_ICALL                                             $26     
         36        ASSIGN                                                       !2, $26
   54    37        INIT_FCALL                                                   'json_encode'
         38        SEND_VAR                                                     !2
         39        DO_ICALL                                             $28     
         40        ECHO                                                         $28
         41      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.69 ms | 2143 KiB | 16 Q