3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "Jan 2016" => 2, "Feb 2016" => 4, "Mar 2016" => 2, "Apr 2016" => 0, "Jan 2017" => 9, "Feb 2017" => 2, "Mar 2017" => 5, "Jan 2018" => 4, "Feb 2018" => 6 ]; $totals = []; foreach ($array as $date => $amount) { $year = substr($date, -4); $totals[$year] = ($totals[$year] ?? 0) + $amount; } var_export($totals);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/409Zl
function name:  (null)
number of ops:  22
compiled vars:  !0 = $array, !1 = $totals, !2 = $amount, !3 = $date, !4 = $year
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   16     2      > FE_RESET_R                                       $7      !0, ->17
          3    > > FE_FETCH_R                                       ~8      $7, !2, ->17
          4    >   ASSIGN                                                   !3, ~8
   17     5        INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !3
          7        SEND_VAL                                                 -4
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !4, $10
   18    10        FETCH_DIM_IS                                     ~13     !1, !4
         11        COALESCE                                         ~14     ~13
         12        QM_ASSIGN                                        ~14     0
         13        ADD                                              ~15     ~14, !2
         14        ASSIGN_DIM                                               !1, !4
         15        OP_DATA                                                  ~15
   16    16      > JMP                                                      ->3
         17    >   FE_FREE                                                  $7
   20    18        INIT_FCALL                                               'var_export'
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.3 ms | 999 KiB | 15 Q