3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array ( "0" => Array ( "2" => 123 ), "1" => Array ( "4" => 45 ), "2" => Array ( "3" => 12 ), "3" => Array ( "5" => 2 ), "4" => Array ( "2" => 12 ), "5" => Array ( "4" => 21 ), "6" => Array ( "2" => 12 ), "7" => Array ( "3" => 21 ), "8" => Array ( "2" => 12 ), "9" => Array ( "3" => 21 ), "10" => Array ( "2" => 2 ), "11" => Array ( "4" => 2 ), "12" => Array ( "2" => 2 ), "13" => Array ( "4" => 2 ), "14" => Array ( "3" => 12 ), "15" => Array ( "4" => 12 ), "16" => Array ( "2" => 12 ), "17" => Array ( "2" => 12 ), "18" => Array ( "4" => 12 ), "19" => Array ( "3" => 12 ), "20" => Array ( "2" => 15 ), "21" => Array ( "4" => 21 ), ); // find all subarray keys (2,3,4,5) foreach($arr as $subarr){ $keys[] = key($subarr); } // remove duplicate keys $keys = array_unique($keys); // sum values with same key from $arr and save to $sums foreach($keys as $key){ $sums[$key] = array_sum(array_column($arr,$key)); } var_dump($sums);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 9
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 9
filename:       /in/F3RJr
function name:  (null)
number of ops:  31
compiled vars:  !0 = $arr, !1 = $subarr, !2 = $keys, !3 = $key, !4 = $sums
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1      > FE_RESET_R                                       $6      !0, ->9
          2    > > FE_FETCH_R                                               $6, !1, ->9
   30     3    >   INIT_FCALL                                               'key'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $8      
          6        ASSIGN_DIM                                               !2
          7        OP_DATA                                                  $8
   29     8      > JMP                                                      ->2
          9    >   FE_FREE                                                  $6
   34    10        INIT_FCALL                                               'array_unique'
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !2, $9
   37    14      > FE_RESET_R                                       $11     !2, ->26
         15    > > FE_FETCH_R                                               $11, !3, ->26
   38    16    >   INIT_FCALL                                               'array_sum'
         17        INIT_FCALL                                               'array_column'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $13     
         21        SEND_VAR                                                 $13
         22        DO_ICALL                                         $14     
         23        ASSIGN_DIM                                               !4, !3
         24        OP_DATA                                                  $14
   37    25      > JMP                                                      ->15
         26    >   FE_FREE                                                  $11
   41    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                                 
         30      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.39 ms | 1007 KiB | 18 Q