3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 'abc-abc-12', 'qty' => 0, 'locationID' => 276, 'CC_qty' => 250, 'Location' => 'NOP11'], ['id' => 'abc-abc-12', 'qty' => 0, 'locationID' => 310, 'CC_qty' => 1385, 'Location' => 'NOP01'], ['id' => 'abc-abc-23', 'qty' => 0, 'locationID' => 84, 'CC_qty' => 116, 'Location' => 'NOP06'], ['id' => 'abc-abc-23', 'qty' => 0, 'locationID' => 254, 'CC_qty' => 432, 'Location' => 'NOP08'], ['id' => 'abc-abc-23', 'qty' => 0, 'locationID' => 228, 'CC_qty' => 101, 'Location' => 'NOP04'], ['id' => 'abc-abc-34', 'qty' => 0, 'locationID' => 254, 'CC_qty' => 436, 'Location' => 'NOP08'], ['id' => 'abc-abc-34', 'qty' => 0, 'locationID' => 254, 'CC_qty' => 62, 'Location' => 'NOP08'], ['id' => 'abc-abc-45', 'qty' => 0, 'locationID' => 75, 'CC_qty' => 89, 'Location' => 'NOP05'], ['id' => 'abc-abc-45', 'qty' => 0, 'locationID' => 202, 'CC_qty' => 372, 'Location' => 'NOP07'], ]; $result = []; foreach ($array as $row) { if (!isset($result[$row['id']])) { $result[$row['id']] = $row; } else { $result[$row['id']]['qty'] += $row['qty']; // SUM $result[$row['id']]['locationID'] .= ", " . $row['locationID']; // CONCAT $result[$row['id']]['CC_qty'] += $row['CC_qty']; // SUM $result[$row['id']]['Location'] .= ", " . $row['Location']; // CONCAT } } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/FqtjX
function name:  (null)
number of ops:  43
compiled vars:  !0 = $array, !1 = $result, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   16     2      > FE_RESET_R                                       $5      !0, ->35
          3    > > FE_FETCH_R                                               $5, !2, ->35
   17     4    >   FETCH_DIM_R                                      ~6      !2, 'id'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !1, ~6
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->12
   18     8    >   FETCH_DIM_R                                      ~9      !2, 'id'
          9        ASSIGN_DIM                                               !1, ~9
         10        OP_DATA                                                  !2
   17    11      > JMP                                                      ->34
   20    12    >   FETCH_DIM_R                                      ~11     !2, 'id'
         13        FETCH_DIM_R                                      ~14     !2, 'qty'
         14        FETCH_DIM_RW                                     $12     !1, ~11
         15        ASSIGN_DIM_OP                +=               1          $12, 'qty'
         16        OP_DATA                                                  ~14
   21    17        FETCH_DIM_R                                      ~15     !2, 'id'
         18        FETCH_DIM_R                                      ~18     !2, 'locationID'
         19        CONCAT                                           ~19     '%2C+', ~18
         20        FETCH_DIM_RW                                     $16     !1, ~15
         21        ASSIGN_DIM_OP                .=               8          $16, 'locationID'
         22        OP_DATA                                                  ~19
   22    23        FETCH_DIM_R                                      ~20     !2, 'id'
         24        FETCH_DIM_R                                      ~23     !2, 'CC_qty'
         25        FETCH_DIM_RW                                     $21     !1, ~20
         26        ASSIGN_DIM_OP                +=               1          $21, 'CC_qty'
         27        OP_DATA                                                  ~23
   23    28        FETCH_DIM_R                                      ~24     !2, 'id'
         29        FETCH_DIM_R                                      ~27     !2, 'Location'
         30        CONCAT                                           ~28     '%2C+', ~27
         31        FETCH_DIM_RW                                     $25     !1, ~24
         32        ASSIGN_DIM_OP                .=               8          $25, 'Location'
         33        OP_DATA                                                  ~28
   16    34    > > JMP                                                      ->3
         35    >   FE_FREE                                                  $5
   26    36        INIT_FCALL                                               'var_export'
         37        INIT_FCALL                                               'array_values'
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                         $29     
         40        SEND_VAR                                                 $29
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.09 ms | 1008 KiB | 15 Q