3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.74 ms | 1396 KiB | 17 Q