3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['id' => 1, 'uid' => 50, 'sum1' => 1, 'sum2' => 2], ['id' => 2, 'uid' => 50, 'sum1' => 2, 'sum2' => 4], ['id' => 3, 'uid' => 51, 'sum1' => 3, 'sum2' => 5], ]; $result = []; foreach ($array as $row) { if (!isset($ref[$row['uid']])) { $ref[$row['uid']] = $row; $result[] =& $ref[$row['uid']]; continue; } $ref[$row['uid']]['sum1'] += $row['sum1']; $ref[$row['uid']]['sum2'] += $row['sum2']; } 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/Fpe8P
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>
    9     1        ASSIGN                                                   !1, <array>
   10     2      > FE_RESET_R                                       $6      !0, ->28
          3    > > FE_FETCH_R                                               $6, !2, ->28
   11     4    >   FETCH_DIM_R                                      ~7      !2, 'uid'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !3, ~7
          6        BOOL_NOT                                         ~9      ~8
          7      > JMPZ                                                     ~9, ->17
   12     8    >   FETCH_DIM_R                                      ~10     !2, 'uid'
          9        ASSIGN_DIM                                               !3, ~10
         10        OP_DATA                                                  !2
   13    11        FETCH_DIM_R                                      ~13     !2, 'uid'
         12        FETCH_DIM_W                                      $14     !3, ~13
         13        MAKE_REF                                         $15     $14
         14        FETCH_DIM_W                                      $12     !1
         15        ASSIGN_REF                                               $12, $15
   14    16      > JMP                                                      ->3
   16    17    >   FETCH_DIM_R                                      ~17     !2, 'uid'
         18        FETCH_DIM_R                                      ~20     !2, 'sum1'
         19        FETCH_DIM_RW                                     $18     !3, ~17
         20        ASSIGN_DIM_OP                +=               1          $18, 'sum1'
         21        OP_DATA                                                  ~20
   17    22        FETCH_DIM_R                                      ~21     !2, 'uid'
         23        FETCH_DIM_R                                      ~24     !2, 'sum2'
         24        FETCH_DIM_RW                                     $22     !3, ~21
         25        ASSIGN_DIM_OP                +=               1          $22, 'sum2'
         26        OP_DATA                                                  ~24
   10    27      > JMP                                                      ->3
         28    >   FE_FREE                                                  $6
   19    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:
136.29 ms | 1001 KiB | 14 Q