3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'GB' => 20827, 'US' => 73, 'ES' => 23, 'AU' => 15, 'DE' => 12, 'MY' => 4, 'QA' => 1, 'VN' => 1, 'SK' => 1, 'FJ' => 1, 'ME' => 1, 'TR' => 1, 'LV' => 1 ], [ 'GB' => 15070, 'US' => 3920, 'IE' => 1711, 'PH' => 1071, 'MT' => 578, 'AU' => 423, 'HR' => 241, 'ZA' => 210, 'FR' => 139 ] ]; $result = []; foreach ($array as $row) { foreach ($row as $key => $value) { $result[$key] = ($result[$key] ?? 0) + $value; } } var_export($result); echo "\n---\n"; var_export( array_reduce( $array, function($result, $row) { foreach ($row as $key => $value) { $result[$key] = ($result[$key] ?? 0) + $value; } return $result; }, [] ) ); echo "\n---\n"; $result = []; array_walk_recursive( $array, function($value, $key) use(&$result) { $result[$key] = ($result[$key] ?? 0) + $value; } ); var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/PR7Ln
function name:  (null)
number of ops:  42
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   32     1        ASSIGN                                                   !1, <array>
   33     2      > FE_RESET_R                                       $7      !0, ->16
          3    > > FE_FETCH_R                                               $7, !2, ->16
   34     4    > > FE_RESET_R                                       $8      !2, ->14
          5    > > FE_FETCH_R                                       ~9      $8, !3, ->14
          6    >   ASSIGN                                                   !4, ~9
   35     7        FETCH_DIM_IS                                     ~12     !1, !4
          8        COALESCE                                         ~13     ~12
          9        QM_ASSIGN                                        ~13     0
         10        ADD                                              ~14     ~13, !3
         11        ASSIGN_DIM                                               !1, !4
         12        OP_DATA                                                  ~14
   34    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $8
   33    15      > JMP                                                      ->3
         16    >   FE_FREE                                                  $7
   38    17        INIT_FCALL                                               'var_export'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
   40    20        ECHO                                                     '%0A---%0A'
   42    21        INIT_FCALL                                               'var_export'
   43    22        INIT_FCALL                                               'array_reduce'
   44    23        SEND_VAR                                                 !0
   45    24        DECLARE_LAMBDA_FUNCTION                          ~16     [0]
   50    25        SEND_VAL                                                 ~16
   51    26        SEND_VAL                                                 <array>
   43    27        DO_ICALL                                         $17     
   51    28        SEND_VAR                                                 $17
   42    29        DO_ICALL                                                 
   55    30        ECHO                                                     '%0A---%0A'
   57    31        ASSIGN                                                   !1, <array>
   58    32        INIT_FCALL                                               'array_walk_recursive'
   59    33        SEND_REF                                                 !0
   60    34        DECLARE_LAMBDA_FUNCTION                          ~20     [1]
         35        BIND_LEXICAL                                             ~20, !1
   62    36        SEND_VAL                                                 ~20
   58    37        DO_ICALL                                                 
   64    38        INIT_FCALL                                               'var_export'
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                                 
         41      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/PR7Ln
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $result, !1 = $row, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   46     2      > FE_RESET_R                                       $4      !1, ->12
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->12
          4    >   ASSIGN                                                   !3, ~5
   47     5        FETCH_DIM_IS                                     ~8      !0, !3
          6        COALESCE                                         ~9      ~8
          7        QM_ASSIGN                                        ~9      0
          8        ADD                                              ~10     ~9, !2
          9        ASSIGN_DIM                                               !0, !3
         10        OP_DATA                                                  ~10
   46    11      > JMP                                                      ->3
         12    >   FE_FREE                                                  $4
   49    13      > RETURN                                                   !0
   50    14*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PR7Ln
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $value, !1 = $key, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   61     3        FETCH_DIM_IS                                     ~4      !2, !1
          4        COALESCE                                         ~5      ~4
          5        QM_ASSIGN                                        ~5      0
          6        ADD                                              ~6      ~5, !0
          7        ASSIGN_DIM                                               !2, !1
          8        OP_DATA                                                  ~6
   62     9      > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.23 ms | 1076 KiB | 16 Q