3v4l.org

run code in 500+ PHP versions simultaneously
<?php $in[] = array('year' => '2010', 'month' => '11', 'grupo' => '2', 'quantity' => 3); $in[] = array('year' => '2010', 'month' => '11', 'grupo' => '3', 'quantity' => 4); $in[] = array('year' => '2011', 'month' => '2', 'grupo' => '2', 'quantity' => 4); $in[] = array('year' => '2011', 'month' => '2', 'grupo' => '2', 'quantity' => 4); $in[] = array('year' => '2012', 'month' => '3', 'grupo' => '4', 'quantity' => 3); $in[] = array('year' => '2012', 'month' => '3', 'grupo' => '4', 'quantity' => 3); $result = []; foreach ($in as $row) { $compositeKey = implode(array_slice($row, 0, 3)); if (!isset($result[$compositeKey])) { $result[$compositeKey] = $row; } else { $result[$compositeKey]['quantity'] += $row['quantity']; } } var_export( array_values($result) );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 33
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 33
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/A4OOV
function name:  (null)
number of ops:  41
compiled vars:  !0 = $in, !1 = $result, !2 = $row, !3 = $compositeKey
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN_DIM                                                   !0
          1        OP_DATA                                                      <array>
    4     2        ASSIGN_DIM                                                   !0
          3        OP_DATA                                                      <array>
    5     4        ASSIGN_DIM                                                   !0
          5        OP_DATA                                                      <array>
    6     6        ASSIGN_DIM                                                   !0
          7        OP_DATA                                                      <array>
    7     8        ASSIGN_DIM                                                   !0
          9        OP_DATA                                                      <array>
    8    10        ASSIGN_DIM                                                   !0
         11        OP_DATA                                                      <array>
   10    12        ASSIGN                                                       !1, <array>
   11    13      > FE_RESET_R                                           $11     !0, ->33
         14    > > FE_FETCH_R                                                   $11, !2, ->33
   12    15    >   INIT_FCALL                                                   'array_slice'
         16        SEND_VAR                                                     !2
         17        SEND_VAL                                                     0
         18        SEND_VAL                                                     3
         19        DO_ICALL                                             $12     
         20        FRAMELESS_ICALL_1                implode             ~13     $12
         21        ASSIGN                                                       !3, ~13
   13    22        ISSET_ISEMPTY_DIM_OBJ                             0  ~15     !1, !3
         23        BOOL_NOT                                             ~16     ~15
         24      > JMPZ                                                         ~16, ->28
   14    25    >   ASSIGN_DIM                                                   !1, !3
         26        OP_DATA                                                      !2
   13    27      > JMP                                                          ->32
   16    28    >   FETCH_DIM_R                                          ~20     !2, 'quantity'
         29        FETCH_DIM_RW                                         $18     !1, !3
         30        ASSIGN_DIM_OP                    +=               1          $18, 'quantity'
         31        OP_DATA                                                      ~20
   11    32    > > JMP                                                          ->14
         33    >   FE_FREE                                                      $11
   19    34        INIT_FCALL                                                   'var_export'
   20    35        INIT_FCALL                                                   'array_values'
         36        SEND_VAR                                                     !1
         37        DO_ICALL                                             $21     
         38        SEND_VAR                                                     $21
   19    39        DO_ICALL                                                     
   21    40      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.28 ms | 1944 KiB | 16 Q