3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ( 0 => array ('User 1', 10, 10), 1 => array ('User 2', 10, 10), 2 => array ('User 1', 10, 10), 3 => array ('User 2', 10, 10), 4 => array ('User 1', 10, 10), 5 => array ('User 3', 10, 10), ); $result = array(); foreach($arr as $val){ $key = array_search($val[0], array_column($result, 0)); if($key !== false){ $result[$key][1] = $result[$key][1] + $val[1]; $result[$key][2] = $result[$key][2] + $val[2]; }else{ $result[] = $val; } } echo "<pre>";print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/DWCgn
function name:  (null)
number of ops:  40
compiled vars:  !0 = $arr, !1 = $result, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $6      !0, ->34
          3    > > FE_FETCH_R                                               $6, !2, ->34
   13     4    >   INIT_FCALL                                               'array_search'
          5        FETCH_DIM_R                                      ~7      !2, 0
          6        SEND_VAL                                                 ~7
          7        INIT_FCALL                                               'array_column'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 0
         10        DO_ICALL                                         $8      
         11        SEND_VAR                                                 $8
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !3, $9
   14    14        TYPE_CHECK                                  1018          !3
         15      > JMPZ                                                     ~11, ->31
   15    16    >   FETCH_DIM_R                                      ~14     !1, !3
         17        FETCH_DIM_R                                      ~15     ~14, 1
         18        FETCH_DIM_R                                      ~16     !2, 1
         19        ADD                                              ~17     ~15, ~16
         20        FETCH_DIM_W                                      $12     !1, !3
         21        ASSIGN_DIM                                               $12, 1
         22        OP_DATA                                                  ~17
   16    23        FETCH_DIM_R                                      ~20     !1, !3
         24        FETCH_DIM_R                                      ~21     ~20, 2
         25        FETCH_DIM_R                                      ~22     !2, 2
         26        ADD                                              ~23     ~21, ~22
         27        FETCH_DIM_W                                      $18     !1, !3
         28        ASSIGN_DIM                                               $18, 2
         29        OP_DATA                                                  ~23
         30      > JMP                                                      ->33
   18    31    >   ASSIGN_DIM                                               !1
         32        OP_DATA                                                  !2
   12    33    > > JMP                                                      ->3
         34    >   FE_FREE                                                  $6
   21    35        ECHO                                                     '%3Cpre%3E'
         36        INIT_FCALL                                               'print_r'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                                 
         39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
128.07 ms | 1405 KiB | 19 Q