3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = [ ['ID' => 1, 'Count' => 2], ]; $b = [ ['ID' => 1, 'Count' => 4], ['ID' => 2, 'Count' => 3] ]; $result = []; foreach (array_merge($a, $b) as $row) { if (!isset($result[$row['ID']])) { $result[$row['ID']] = $row; } else { $result[$row['ID']]['Count'] += $row['Count']; } } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/9N5WV
function name:  (null)
number of ops:  31
compiled vars:  !0 = $a, !1 = $b, !2 = $result, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, <array>
   12     2        ASSIGN                                                   !2, <array>
   13     3        INIT_FCALL                                               'array_merge'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7      > FE_RESET_R                                       $8      $7, ->23
          8    > > FE_FETCH_R                                               $8, !3, ->23
   14     9    >   FETCH_DIM_R                                      ~9      !3, 'ID'
         10        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !2, ~9
         11        BOOL_NOT                                         ~11     ~10
         12      > JMPZ                                                     ~11, ->17
   15    13    >   FETCH_DIM_R                                      ~12     !3, 'ID'
         14        ASSIGN_DIM                                               !2, ~12
         15        OP_DATA                                                  !3
   14    16      > JMP                                                      ->22
   17    17    >   FETCH_DIM_R                                      ~14     !3, 'ID'
         18        FETCH_DIM_R                                      ~17     !3, 'Count'
         19        FETCH_DIM_RW                                     $15     !2, ~14
         20        ASSIGN_DIM_OP                +=               1          $15, 'Count'
         21        OP_DATA                                                  ~17
   13    22    > > JMP                                                      ->8
         23    >   FE_FREE                                                  $8
   20    24        INIT_FCALL                                               'var_export'
         25        INIT_FCALL                                               'array_values'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                         $18     
         28        SEND_VAR                                                 $18
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.49 ms | 1003 KiB | 16 Q