3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['group' => 'Apple', 'num' => 5, 'price' => 10], ['group' => 'Apple', 'num' => 2, 'price' => 8], ['group' => 'Orange', 'num' => 4, 'price' => 6], ['group' => 'Orange', 'num' => 12, 'price' => 24], ]; $result = []; foreach ($array as $row) { if (!isset($ref[$row['group']])) { $ref[$row['group']] = $row; $result[] =& $ref[$row['group']]; continue; } $ref[$row['group']]['num'] += $row['num']; $ref[$row['group']]['price'] += $row['price']; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 28
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/K2Jsn
function name:  (null)
number of ops:  33
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $6      !0, ->28
          3    > > FE_FETCH_R                                               $6, !2, ->28
   12     4    >   FETCH_DIM_R                                      ~7      !2, 'group'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !3, ~7
          6        BOOL_NOT                                         ~9      ~8
          7      > JMPZ                                                     ~9, ->17
   13     8    >   FETCH_DIM_R                                      ~10     !2, 'group'
          9        ASSIGN_DIM                                               !3, ~10
         10        OP_DATA                                                  !2
   14    11        FETCH_DIM_R                                      ~13     !2, 'group'
         12        FETCH_DIM_W                                      $14     !3, ~13
         13        MAKE_REF                                         $15     $14
         14        FETCH_DIM_W                                      $12     !1
         15        ASSIGN_REF                                               $12, $15
   15    16      > JMP                                                      ->3
   17    17    >   FETCH_DIM_R                                      ~17     !2, 'group'
         18        FETCH_DIM_R                                      ~20     !2, 'num'
         19        FETCH_DIM_RW                                     $18     !3, ~17
         20        ASSIGN_DIM_OP                +=               1          $18, 'num'
         21        OP_DATA                                                  ~20
   18    22        FETCH_DIM_R                                      ~21     !2, 'group'
         23        FETCH_DIM_R                                      ~24     !2, 'price'
         24        FETCH_DIM_RW                                     $22     !3, ~21
         25        ASSIGN_DIM_OP                +=               1          $22, 'price'
         26        OP_DATA                                                  ~24
   11    27      > JMP                                                      ->3
         28    >   FE_FREE                                                  $6
   20    29        INIT_FCALL                                               'var_export'
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                                 
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
204.76 ms | 1011 KiB | 14 Q