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 ]; foreach ($array as $date => &$amount) { $year = substr($date, -4); $amount = ['month' => $amount, 'total' => &$ref[$year]]; $ref[$year] = ($ref[$year] ?? 0) + $amount['month']; } var_export($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 21
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/t9k6a
function name:  (null)
number of ops:  26
compiled vars:  !0 = $array, !1 = $amount, !2 = $date, !3 = $year, !4 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1      > FE_RESET_RW                                      $6      !0, ->21
          2    > > FE_FETCH_RW                                      ~7      $6, !1, ->21
          3    >   ASSIGN                                                   !2, ~7
   16     4        INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 -4
          7        DO_ICALL                                         $9      
          8        ASSIGN                                                   !3, $9
   17     9        INIT_ARRAY                                       ~11     !1, 'month'
         10        FETCH_DIM_W                                      $12     !4, !3
         11        ADD_ARRAY_ELEMENT                                ~11     $12, 'total'
         12        ASSIGN                                                   !1, ~11
   18    13        FETCH_DIM_IS                                     ~15     !4, !3
         14        COALESCE                                         ~16     ~15
         15        QM_ASSIGN                                        ~16     0
         16        FETCH_DIM_R                                      ~17     !1, 'month'
         17        ADD                                              ~18     ~16, ~17
         18        ASSIGN_DIM                                               !4, !3
         19        OP_DATA                                                  ~18
   15    20      > JMP                                                      ->2
         21    >   FE_FREE                                                  $6
   20    22        INIT_FCALL                                               'var_export'
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.12 ms | 999 KiB | 15 Q