3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ (object)['id' => 1, 'nome' => 'T.SHIRT', 'quantita' => 2,], (object)['id' => 2, 'nome' => 'Sweatshirt', 'quantita' => 4,], (object)['id' => 1, 'nome' => 'T.SHIRT', 'quantita' => 4,], ]; $store = []; foreach($arr as $record) { if(isset($store[$record->id])) { $store[$record->id]->quantita += $record->quantita; } else $store[$record->id] = $record; } var_dump($store);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
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 = 9
Branch analysis from position: 9
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/b94aU
function name:  (null)
number of ops:  28
compiled vars:  !0 = $arr, !1 = $store, !2 = $record
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   CAST                                          8  ~3      <array>
          1        INIT_ARRAY                                       ~4      ~3
    4     2        CAST                                          8  ~5      <array>
          3        ADD_ARRAY_ELEMENT                                ~4      ~5
    5     4        CAST                                          8  ~6      <array>
          5        ADD_ARRAY_ELEMENT                                ~4      ~6
    2     6        ASSIGN                                                   !0, ~4
    8     7        ASSIGN                                                   !1, <array>
    9     8      > FE_RESET_R                                       $9      !0, ->23
          9    > > FE_FETCH_R                                               $9, !2, ->23
   10    10    >   FETCH_OBJ_R                                      ~10     !2, 'id'
         11        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~10
         12      > JMPZ                                                     ~11, ->19
   11    13    >   FETCH_OBJ_R                                      ~12     !2, 'id'
         14        FETCH_OBJ_R                                      ~15     !2, 'quantita'
         15        FETCH_DIM_RW                                     $13     !1, ~12
         16        ASSIGN_OBJ_OP                                 1          $13, 'quantita'
         17        OP_DATA                                                  ~15
   10    18      > JMP                                                      ->22
   12    19    >   FETCH_OBJ_R                                      ~16     !2, 'id'
         20        ASSIGN_DIM                                               !1, ~16
         21        OP_DATA                                                  !2
    9    22    > > JMP                                                      ->9
         23    >   FE_FREE                                                  $9
   15    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.7 ms | 1011 KiB | 14 Q