3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = [ ['part' => '1', 'address' => 'aaa', 'type' => '1', 'count' => 5], ['part' => '1', 'address' => 'bbb', 'type' => '1', 'count' => 5], ['part' => '1', 'address' => 'ccc', 'type' => '1', 'count' => 5], ['part' => '2', 'address' => 'aaa', 'type' => '1', 'count' => 5], ['part' => '2', 'address' => 'bbb', 'type' => '1', 'count' => 5], ['part' => '2', 'address' => 'ccc', 'type' => '2', 'count' => 5] ]; $result = []; foreach ($arr1 as $row) { $compositeKey = $row['part'] . '-' . $row['type']; $result[$compositeKey] = [ 'part' => $row['part'], 'type' => $row['type'], 'count' => ($result[$compositeKey]['count'] ?? 0) + $row['count'] ]; } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/2auVN
function name:  (null)
number of ops:  31
compiled vars:  !0 = $arr1, !1 = $result, !2 = $row, !3 = $compositeKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   13     2      > FE_RESET_R                                       $6      !0, ->23
          3    > > FE_FETCH_R                                               $6, !2, ->23
   14     4    >   FETCH_DIM_R                                      ~7      !2, 'part'
          5        CONCAT                                           ~8      ~7, '-'
          6        FETCH_DIM_R                                      ~9      !2, 'type'
          7        CONCAT                                           ~10     ~8, ~9
          8        ASSIGN                                                   !3, ~10
   16     9        FETCH_DIM_R                                      ~13     !2, 'part'
         10        INIT_ARRAY                                       ~14     ~13, 'part'
   17    11        FETCH_DIM_R                                      ~15     !2, 'type'
         12        ADD_ARRAY_ELEMENT                                ~14     ~15, 'type'
   18    13        FETCH_DIM_IS                                     ~16     !1, !3
         14        FETCH_DIM_IS                                     ~17     ~16, 'count'
         15        COALESCE                                         ~18     ~17
         16        QM_ASSIGN                                        ~18     0
         17        FETCH_DIM_R                                      ~19     !2, 'count'
         18        ADD                                              ~20     ~18, ~19
         19        ADD_ARRAY_ELEMENT                                ~14     ~20, 'count'
   15    20        ASSIGN_DIM                                               !1, !3
   18    21        OP_DATA                                                  ~14
   13    22      > JMP                                                      ->3
         23    >   FE_FREE                                                  $6
   21    24        INIT_FCALL                                               'var_export'
         25        INIT_FCALL                                               'array_values'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                         $21     
         28        SEND_VAR                                                 $21
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135 ms | 1000 KiB | 15 Q