3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [ '2012' => ['1' => 13, '2' => 22, '3' => 18, '5' => 19], '2011' => ['1' => '4', '3' => 13], ]; $array2 = [ '2012' => ['1' => 44, '4' => 34, '5' => 38, '6' => 29], '2011' => ['1' => 9, '2' => 11, '3' => 1], ]; $array3 = [ '2012' => ['2' => 5, '4' => 3, '6' => 1, '8' => 11], '2011' => ['3' => 9, '4' => 14, '9' => 9], ]; $defaults = array_fill_keys(range(1, 12), 0); $result = []; foreach ([$array1, $array2, $array3] as $array) { foreach ($array as $year => $row) { $result[$year] ??= $defaults; foreach ($row as $m => $v) { $result[$year][$m] += $v; } } } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 38
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 36
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 36
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 36
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/68XoB
function name:  (null)
number of ops:  43
compiled vars:  !0 = $array1, !1 = $array2, !2 = $array3, !3 = $defaults, !4 = $result, !5 = $array, !6 = $row, !7 = $year, !8 = $v, !9 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   13     2        ASSIGN                                                   !2, <array>
   18     3        INIT_FCALL                                               'array_fill_keys'
          4        INIT_FCALL                                               'range'
          5        SEND_VAL                                                 1
          6        SEND_VAL                                                 12
          7        DO_ICALL                                         $13     
          8        SEND_VAR                                                 $13
          9        SEND_VAL                                                 0
         10        DO_ICALL                                         $14     
         11        ASSIGN                                                   !3, $14
   19    12        ASSIGN                                                   !4, <array>
   20    13        INIT_ARRAY                                       ~17     !0
         14        ADD_ARRAY_ELEMENT                                ~17     !1
         15        ADD_ARRAY_ELEMENT                                ~17     !2
         16      > FE_RESET_R                                       $18     ~17, ->38
         17    > > FE_FETCH_R                                               $18, !5, ->38
   21    18    > > FE_RESET_R                                       $19     !5, ->36
         19    > > FE_FETCH_R                                       ~20     $19, !6, ->36
         20    >   ASSIGN                                                   !7, ~20
   22    21        FETCH_DIM_IS                                     ~22     !4, !7
         22        COALESCE                                         ~23     ~22
         23        ASSIGN_DIM                                       ~24     !4, !7
         24        OP_DATA                                                  !3
         25        QM_ASSIGN                                        ~23     ~24
         26        FREE                                                     ~23
   23    27      > FE_RESET_R                                       $25     !6, ->34
         28    > > FE_FETCH_R                                       ~26     $25, !8, ->34
         29    >   ASSIGN                                                   !9, ~26
   24    30        FETCH_DIM_RW                                     $28     !4, !7
         31        ASSIGN_DIM_OP                +=               1          $28, !9
         32        OP_DATA                                                  !8
   23    33      > JMP                                                      ->28
         34    >   FE_FREE                                                  $25
   21    35      > JMP                                                      ->19
         36    >   FE_FREE                                                  $19
   20    37      > JMP                                                      ->17
         38    >   FE_FREE                                                  $18
   28    39        INIT_FCALL                                               'var_export'
         40        SEND_VAR                                                 !4
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.95 ms | 1017 KiB | 16 Q