3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array ( '0' => Array ( 'emp_firstname' => 'Alistair', 'non_pm' => 'AMZ', 'sum' => 2 ), '1' => Array ( 'emp_firstname' => 'Shakkeer', 'non_pm' => 'SHK', 'sum' => 3 ), '2' => Array ( 'emp_firstname' => 'Waqas', 'non_pm' => 'WAS', 'sum' => 12 ), '3' => Array ( 'emp_firstname' => 'Zain', 'non_pm' => 'ZAI', 'sum' => 9 ), '4' => Array ( 'emp_firstname' => 'Shakkeer', 'gud_pmeditor' => 'SHK', 'sum' => 4 ), '5' => Array ( 'emp_firstname' => 'Zain', 'gud_pmeditor' => 'ZAI', 'sum' => 2 ) ); $res=[]; foreach($arr as $val){ if(array_key_exists($val['emp_firstname'], $res)) $res[$val['emp_firstname']]['sum'] = ($res[$val['emp_firstname']]['sum'] + $val['sum']); else $res[$val['emp_firstname']] = $val; } print_r(array_values($res));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
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: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/CAoVb
function name:  (null)
number of ops:  29
compiled vars:  !0 = $arr, !1 = $res, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   51     1        ASSIGN                                                   !1, <array>
   52     2      > FE_RESET_R                                       $5      !0, ->21
          3    > > FE_FETCH_R                                               $5, !2, ->21
   53     4    >   FETCH_DIM_R                                      ~6      !2, 'emp_firstname'
          5        ARRAY_KEY_EXISTS                                         ~6, !1
          6      > JMPZ                                                     ~7, ->17
   54     7    >   FETCH_DIM_R                                      ~8      !2, 'emp_firstname'
          8        FETCH_DIM_R                                      ~11     !2, 'emp_firstname'
          9        FETCH_DIM_R                                      ~12     !1, ~11
         10        FETCH_DIM_R                                      ~13     ~12, 'sum'
         11        FETCH_DIM_R                                      ~14     !2, 'sum'
         12        ADD                                              ~15     ~13, ~14
         13        FETCH_DIM_W                                      $9      !1, ~8
         14        ASSIGN_DIM                                               $9, 'sum'
         15        OP_DATA                                                  ~15
   53    16      > JMP                                                      ->20
   56    17    >   FETCH_DIM_R                                      ~16     !2, 'emp_firstname'
         18        ASSIGN_DIM                                               !1, ~16
         19        OP_DATA                                                  !2
   52    20    > > JMP                                                      ->3
         21    >   FE_FREE                                                  $5
   58    22        INIT_FCALL                                               'print_r'
         23        INIT_FCALL                                               'array_values'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $18     
         26        SEND_VAR                                                 $18
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.66 ms | 1439 KiB | 15 Q