3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ [ 'id' => 1331, 'label' => 'PMI', 'cost' => 98.25, 'cid' => 22, 'product_id' => 133, ], [ 'id' => 1341, 'label' => 'PMI', 'cost' => 98.25, 'cid' => 22, 'product_id' => 134, ], ]; $output = []; foreach ($data as $item) { if (!isset($output[$item['cid']])) { $output[$item['cid']] = [ 'label' => $item['label'], 'cost' => 0, 'cid' => $item['cid'], ]; } $output[$item['cid']]['cost'] += $item['cost']; } print_r($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/MY6Xu
function name:  (null)
number of ops:  27
compiled vars:  !0 = $data, !1 = $output, !2 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   20     1        ASSIGN                                                       !1, <array>
   21     2      > FE_RESET_R                                           $5      !0, ->22
          3    > > FE_FETCH_R                                                   $5, !2, ->22
   22     4    >   FETCH_DIM_R                                          ~6      !2, 'cid'
          5        ISSET_ISEMPTY_DIM_OBJ                             0  ~7      !1, ~6
          6        BOOL_NOT                                             ~8      ~7
          7      > JMPZ                                                         ~8, ->16
   23     8    >   FETCH_DIM_R                                          ~9      !2, 'cid'
   24     9        FETCH_DIM_R                                          ~11     !2, 'label'
         10        INIT_ARRAY                                           ~12     ~11, 'label'
   25    11        ADD_ARRAY_ELEMENT                                    ~12     0, 'cost'
   26    12        FETCH_DIM_R                                          ~13     !2, 'cid'
         13        ADD_ARRAY_ELEMENT                                    ~12     ~13, 'cid'
   23    14        ASSIGN_DIM                                                   !1, ~9
   26    15        OP_DATA                                                      ~12
   30    16    >   FETCH_DIM_R                                          ~14     !2, 'cid'
         17        FETCH_DIM_R                                          ~17     !2, 'cost'
         18        FETCH_DIM_RW                                         $15     !1, ~14
         19        ASSIGN_DIM_OP                    +=               1          $15, 'cost'
         20        OP_DATA                                                      ~17
   21    21      > JMP                                                          ->3
         22    >   FE_FREE                                                      $5
   33    23        INIT_FCALL                                                   'print_r'
         24        SEND_VAR                                                     !1
         25        DO_ICALL                                                     
         26      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.91 ms | 1902 KiB | 14 Q