3v4l.org

run code in 500+ PHP versions simultaneously
<?php $startArr = json_decode('[ { "meterid": 23484, "expired_total": 1 }, { "meterid": 23489, "expired_total": 3 } ]', true); $expArr = json_decode('[ { "meterid": 23478, "start_total": 1 }, { "meterid": 23489, "start_total": 1 }, { "meterid": 23490, "start_total": 2 } ]', true); // $output_result { "23478": { "meterid": 23478, "start_total": 1, "expired_total": 0 }, "23484": { "meterid": 23484, "start_total": 0, "expired_total": 1 } "23489": { "meterid": 23489, "start_total": 1, "expired_total": 3 } "23490": { "meterid": 23490, "start_total": 2, "expired_total": 0 } } $result = []; $default = array_fill_keys(['meterid', 'start_total', 'expired_total'], 0); foreach (array_merge($startArr, $expArr) as $row) { if (!isset($result[$row['meterid']])) { $result[$row['meterid']] = array_replace($default, $row); } else { $result[$row['meterid']] += $row; } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 38
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 38
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/Y4kTA
function name:  (null)
number of ops:  43
compiled vars:  !0 = $startArr, !1 = $expArr, !2 = $result, !3 = $default, !4 = $row
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'json_decode'
          1        SEND_VAL                                                     '%5B+%7B+%22meterid%22%3A+23484%2C+%22expired_total%22%3A+1+%7D%2C+%7B+%22meterid%22%3A+23489%2C+%22expired_total%22%3A+3+%7D+%5D'
          2        SEND_VAL                                                     <true>
          3        DO_ICALL                                             $5      
          4        ASSIGN                                                       !0, $5
    5     5        INIT_FCALL                                                   'json_decode'
          6        SEND_VAL                                                     '%5B+%7B+%22meterid%22%3A+23478%2C+%22start_total%22%3A+1+%7D%2C+%7B+%22meterid%22%3A+23489%2C+%22start_total%22%3A+1+%7D%2C+%7B+%22meterid%22%3A+23490%2C+%22start_total%22%3A+2+%7D+%5D'
          7        SEND_VAL                                                     <true>
          8        DO_ICALL                                             $7      
          9        ASSIGN                                                       !1, $7
    9    10        ASSIGN                                                       !2, <array>
   10    11        INIT_FCALL                                                   'array_fill_keys'
         12        SEND_VAL                                                     <array>
         13        SEND_VAL                                                     0
         14        DO_ICALL                                             $10     
         15        ASSIGN                                                       !3, $10
   11    16        INIT_FCALL                                                   'array_merge'
         17        SEND_VAR                                                     !0
         18        SEND_VAR                                                     !1
         19        DO_ICALL                                             $12     
         20      > FE_RESET_R                                           $13     $12, ->38
         21    > > FE_FETCH_R                                                   $13, !4, ->38
   12    22    >   FETCH_DIM_R                                          ~14     !4, 'meterid'
         23        ISSET_ISEMPTY_DIM_OBJ                             0  ~15     !2, ~14
         24        BOOL_NOT                                             ~16     ~15
         25      > JMPZ                                                         ~16, ->34
   13    26    >   FETCH_DIM_R                                          ~17     !4, 'meterid'
         27        INIT_FCALL                                                   'array_replace'
         28        SEND_VAR                                                     !3
         29        SEND_VAR                                                     !4
         30        DO_ICALL                                             $19     
         31        ASSIGN_DIM                                                   !2, ~17
         32        OP_DATA                                                      $19
   12    33      > JMP                                                          ->37
   15    34    >   FETCH_DIM_R                                          ~20     !4, 'meterid'
         35        ASSIGN_DIM_OP                    +=               1          !2, ~20
         36        OP_DATA                                                      !4
   11    37    > > JMP                                                          ->21
         38    >   FE_FREE                                                      $13
   18    39        INIT_FCALL                                                   'var_export'
         40        SEND_VAR                                                     !2
         41        DO_ICALL                                                     
         42      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.02 ms | 1963 KiB | 18 Q