3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 121 => [ "number" => 121, "name" => "Some Name 1", "value" => "2.222" ], 116 => [ "number" => 116, "name" => "Some Name 2", "value" => "1.111" ], 1 => [ "number" => 1, "name" => "Some Name 3", "value" => "1.232" ] ], [ 121 => [ "number" => 121, "name" => "Some Name 1", "value" => "1.111" ], 116 => [ "number" => 116, "name" => "Some Name 2", "value" => "2.222" ], 1 => [ "number" => 1, "name" => "Some Name 3", "value" => "3.111" ] ] ]; $all_numbers=array_keys($array[0]); foreach($all_numbers as $number){ $array[0][$number]['value']=array_sum(array_column(array_column($array,$number),'value')); } $array=[$array[0]]; /* foreach($array as &$group){ var_export(array_column($group,'121')); //foreach($group as $number=>$subarray){ // $group[$number]['value']=array_sum(array_column($group,$number)); //} break; } */ var_export($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/kLPSO
function name:  (null)
number of ops:  32
compiled vars:  !0 = $array, !1 = $all_numbers, !2 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        INIT_FCALL                                               'array_keys'
          2        FETCH_DIM_R                                      ~4      !0, 0
          3        SEND_VAL                                                 ~4
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   17     6      > FE_RESET_R                                       $7      !1, ->24
          7    > > FE_FETCH_R                                               $7, !2, ->24
   18     8    >   INIT_FCALL                                               'array_sum'
          9        INIT_FCALL                                               'array_column'
         10        INIT_FCALL                                               'array_column'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                         $11     
         14        SEND_VAR                                                 $11
         15        SEND_VAL                                                 'value'
         16        DO_ICALL                                         $12     
         17        SEND_VAR                                                 $12
         18        DO_ICALL                                         $13     
         19        FETCH_DIM_W                                      $8      !0, 0
         20        FETCH_DIM_W                                      $9      $8, !2
         21        ASSIGN_DIM                                               $9, 'value'
         22        OP_DATA                                                  $13
   17    23      > JMP                                                      ->7
         24    >   FE_FREE                                                  $7
   20    25        FETCH_DIM_R                                      ~14     !0, 0
         26        INIT_ARRAY                                       ~15     ~14
         27        ASSIGN                                                   !0, ~15
   30    28        INIT_FCALL                                               'var_export'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.27 ms | 1014 KiB | 17 Q