3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( array('delivery_plan' => '80::2020/07', 'additional_amount_usd' => 32.88), array('delivery_plan' => '80::2020/09', 'additional_amount_usd' => 16.44), array('delivery_plan' => '80::2020/07', 'additional_amount_usd' => 32.88), ); $sum_array = []; foreach ($array as $item) { if (!isset($sum_array[$item['delivery_plan']])) { // initialization $sum_array[$item['delivery_plan']] = ['delivery_plan' => $item['delivery_plan'], 'additional_amount_usd' => 0.0]; } $sum_array[$item['delivery_plan']]['additional_amount_usd'] += $item['additional_amount_usd']; } $sum_array = array_values($sum_array); print_r($sum_array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/h9Q5L
function name:  (null)
number of ops:  29
compiled vars:  !0 = $array, !1 = $sum_array, !2 = $item
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                                       $5      !0, ->20
          3    > > FE_FETCH_R                                               $5, !2, ->20
   11     4    >   FETCH_DIM_R                                      ~6      !2, 'delivery_plan'
          5        ISSET_ISEMPTY_DIM_OBJ                         0  ~7      !1, ~6
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->14
   12     8    >   FETCH_DIM_R                                      ~9      !2, 'delivery_plan'
          9        FETCH_DIM_R                                      ~11     !2, 'delivery_plan'
         10        INIT_ARRAY                                       ~12     ~11, 'delivery_plan'
         11        ADD_ARRAY_ELEMENT                                ~12     0, 'additional_amount_usd'
         12        ASSIGN_DIM                                               !1, ~9
         13        OP_DATA                                                  ~12
   14    14    >   FETCH_DIM_R                                      ~13     !2, 'delivery_plan'
         15        FETCH_DIM_R                                      ~16     !2, 'additional_amount_usd'
         16        FETCH_DIM_RW                                     $14     !1, ~13
         17        ASSIGN_DIM_OP                +=               1          $14, 'additional_amount_usd'
         18        OP_DATA                                                  ~16
   10    19      > JMP                                                      ->3
         20    >   FE_FREE                                                  $5
   17    21        INIT_FCALL                                               'array_values'
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                         $17     
         24        ASSIGN                                                   !1, $17
   18    25        INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.23 ms | 1002 KiB | 15 Q