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) { $result[$row['meterid']] = array_replace($result[$row['meterid']] ?? $default, $row); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
2 jumps found. (Code = 78) Position 1 = 22, Position 2 = 34
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/X7hrN
function name:  (null)
number of ops:  39
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, ->34
         21    > > FE_FETCH_R                                                   $13, !4, ->34
   12    22    >   FETCH_DIM_R                                          ~14     !4, 'meterid'
         23        INIT_FCALL                                                   'array_replace'
         24        FETCH_DIM_R                                          ~16     !4, 'meterid'
         25        FETCH_DIM_IS                                         ~17     !2, ~16
         26        COALESCE                                             ~18     ~17
         27        QM_ASSIGN                                            ~18     !3
         28        SEND_VAL                                                     ~18
         29        SEND_VAR                                                     !4
         30        DO_ICALL                                             $19     
         31        ASSIGN_DIM                                                   !2, ~14
         32        OP_DATA                                                      $19
   11    33      > JMP                                                          ->21
         34    >   FE_FREE                                                      $13
   14    35        INIT_FCALL                                                   'var_export'
         36        SEND_VAR                                                     !2
         37        DO_ICALL                                                     
         38      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.69 ms | 1963 KiB | 18 Q