3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = Array ( '0' => Array ( 'ac_no' => 100001, 'amount' => 0.00 ), '1' => Array ( 'ac_no' => 100001, 'amount' => 51255.11 ), '2' => Array ( 'ac_no' => 100001, 'amount' => -500.00 ), '3' => Array ( 'ac_no' => 100001, 'amount' => -621.05 ), '4' => Array ( 'ac_no' => 100002, 'amount' => .00 ), '5' => Array ( 'ac_no' => 100003, 'amount' => .00 ), '6' => Array ( 'ac_no' => 100004, 'amount' => 20714.00 ), '7' => Array ( 'ac_no' => 100004, 'amount' => 0.00 ) ); $acNoWiseArray = []; foreach($array as $arr){ $acNoWiseArray[$arr['ac_no']]['sum'][] = $arr['amount']; } $finalArray = []; foreach($acNoWiseArray as $key=>&$value){ foreach($value['sum'] as $k=> $val){ $finalArray[$key]['new_sum'][] = (is_array($value)) ? array_sum($value['sum']) : $value['sum'][$k]; array_shift($value['sum']); } } print_r($finalArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
2 jumps found. (Code = 125) Position 1 = 14, Position 2 = 42
Branch analysis from position: 14
2 jumps found. (Code = 126) Position 1 = 15, Position 2 = 42
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 40
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 40
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 28
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 40
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 11
filename:       /in/duoEc
function name:  (null)
number of ops:  47
compiled vars:  !0 = $array, !1 = $acNoWiseArray, !2 = $arr, !3 = $finalArray, !4 = $value, !5 = $key, !6 = $val, !7 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   55     1        ASSIGN                                                       !1, <array>
   57     2      > FE_RESET_R                                           $10     !0, ->11
          3    > > FE_FETCH_R                                                   $10, !2, ->11
   58     4    >   FETCH_DIM_R                                          ~11     !2, 'ac_no'
          5        FETCH_DIM_R                                          ~15     !2, 'amount'
          6        FETCH_DIM_W                                          $12     !1, ~11
          7        FETCH_DIM_W                                          $13     $12, 'sum'
          8        ASSIGN_DIM                                                   $13
          9        OP_DATA                                                      ~15
   57    10      > JMP                                                          ->3
         11    >   FE_FREE                                                      $10
   62    12        ASSIGN                                                       !3, <array>
   63    13      > FE_RESET_RW                                          $17     !1, ->42
         14    > > FE_FETCH_RW                                          ~18     $17, !4, ->42
         15    >   ASSIGN                                                       !5, ~18
   64    16        FETCH_DIM_R                                          ~20     !4, 'sum'
         17      > FE_RESET_R                                           $21     ~20, ->40
         18    > > FE_FETCH_R                                           ~22     $21, !6, ->40
         19    >   ASSIGN                                                       !7, ~22
   65    20        TYPE_CHECK                                      128          !4
         21      > JMPZ                                                         ~27, ->28
         22    >   INIT_FCALL                                                   'array_sum'
         23        FETCH_DIM_R                                          ~28     !4, 'sum'
         24        SEND_VAL                                                     ~28
         25        DO_ICALL                                             $29     
         26        QM_ASSIGN                                            ~30     $29
         27      > JMP                                                          ->31
         28    >   FETCH_DIM_R                                          ~31     !4, 'sum'
         29        FETCH_DIM_R                                          ~32     ~31, !7
         30        QM_ASSIGN                                            ~30     ~32
         31    >   FETCH_DIM_W                                          $24     !3, !5
         32        FETCH_DIM_W                                          $25     $24, 'new_sum'
         33        ASSIGN_DIM                                                   $25
         34        OP_DATA                                                      ~30
   66    35        INIT_FCALL                                                   'array_shift'
         36        FETCH_DIM_W                                          $33     !4, 'sum'
         37        SEND_REF                                                     $33
         38        DO_ICALL                                                     
   64    39      > JMP                                                          ->18
         40    >   FE_FREE                                                      $21
   63    41      > JMP                                                          ->14
         42    >   FE_FREE                                                      $17
   72    43        INIT_FCALL                                                   'print_r'
         44        SEND_VAR                                                     !3
         45        DO_ICALL                                                     
         46      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
175.33 ms | 1990 KiB | 16 Q