3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data[2020] = array_fill_keys(range(1,12), '1,000'); $data[2021] = array_fill_keys(range(1,8), '1,500'); $data[2021][9] = null; $data[2021][10] = null; $data[2021][11] = null; $data[2021][12] = null; $thisYear = $year ?? date('Y'); $lastYear = $thisYear - 1; $thisYearRunningTotal = 0; $lastYearRunningTotal = 0; $result = []; for ($month = 1; $month <= 12; ++$month) { $thisYearMonthTotal = $data[$thisYear][$month]; // from model $thisYearRunningTotal = $thisYearMonthTotal === null ? null : (int)str_replace(',', '', $thisYearMonthTotal) + $thisYearRunningTotal; $lastYearMonthTotal = $data[$lastYear][$month]; // from model $lastYearRunningTotal = $lastYearMonthTotal === null ? null : (int)str_replace(',', '', $lastYearMonthTotal) + ($lastYearRunningTotal ?? 0); $result[] = [ 'month' => $month, 'total_now' => $thisYearRunningTotal, 'total_before' => $lastYearRunningTotal, ]; } var_export($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 79
Branch analysis from position: 79
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 45
Branch analysis from position: 81
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 52
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 65
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 45
Branch analysis from position: 81
Branch analysis from position: 45
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 81, Position 2 = 45
Branch analysis from position: 81
Branch analysis from position: 45
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 65
Branch analysis from position: 63
Branch analysis from position: 65
filename:       /in/XKvfJ
function name:  (null)
number of ops:  85
compiled vars:  !0 = $data, !1 = $thisYear, !2 = $year, !3 = $lastYear, !4 = $thisYearRunningTotal, !5 = $lastYearRunningTotal, !6 = $result, !7 = $month, !8 = $thisYearMonthTotal, !9 = $lastYearMonthTotal
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'array_fill_keys'
          1        INIT_FCALL                                                   'range'
          2        SEND_VAL                                                     1
          3        SEND_VAL                                                     12
          4        DO_ICALL                                             $11     
          5        SEND_VAR                                                     $11
          6        SEND_VAL                                                     '1%2C000'
          7        DO_ICALL                                             $12     
          8        ASSIGN_DIM                                                   !0, 2020
          9        OP_DATA                                                      $12
    4    10        INIT_FCALL                                                   'array_fill_keys'
         11        INIT_FCALL                                                   'range'
         12        SEND_VAL                                                     1
         13        SEND_VAL                                                     8
         14        DO_ICALL                                             $14     
         15        SEND_VAR                                                     $14
         16        SEND_VAL                                                     '1%2C500'
         17        DO_ICALL                                             $15     
         18        ASSIGN_DIM                                                   !0, 2021
         19        OP_DATA                                                      $15
    5    20        FETCH_DIM_W                                          $16     !0, 2021
         21        ASSIGN_DIM                                                   $16, 9
         22        OP_DATA                                                      null
    6    23        FETCH_DIM_W                                          $18     !0, 2021
         24        ASSIGN_DIM                                                   $18, 10
         25        OP_DATA                                                      null
    7    26        FETCH_DIM_W                                          $20     !0, 2021
         27        ASSIGN_DIM                                                   $20, 11
         28        OP_DATA                                                      null
    8    29        FETCH_DIM_W                                          $22     !0, 2021
         30        ASSIGN_DIM                                                   $22, 12
         31        OP_DATA                                                      null
   10    32        COALESCE                                             ~24     !2
         33        INIT_FCALL                                                   'date'
         34        SEND_VAL                                                     'Y'
         35        DO_ICALL                                             $25     
         36        QM_ASSIGN                                            ~24     $25
         37        ASSIGN                                                       !1, ~24
   11    38        SUB                                                  ~27     !1, 1
         39        ASSIGN                                                       !3, ~27
   12    40        ASSIGN                                                       !4, 0
   13    41        ASSIGN                                                       !5, 0
   14    42        ASSIGN                                                       !6, <array>
   15    43        ASSIGN                                                       !7, 1
         44      > JMP                                                          ->79
   16    45    >   FETCH_DIM_R                                          ~33     !0, !1
         46        FETCH_DIM_R                                          ~34     ~33, !7
         47        ASSIGN                                                       !8, ~34
   17    48        TYPE_CHECK                                        2          !8
         49      > JMPZ                                                         ~36, ->52
   18    50    >   QM_ASSIGN                                            ~37     null
         51      > JMP                                                          ->57
   19    52    >   FRAMELESS_ICALL_3                str_replace         ~38     '%2C', ''
         53        OP_DATA                                                      !8
         54        CAST                                              4  ~39     ~38
         55        ADD                                                  ~40     ~39, !4
         56        QM_ASSIGN                                            ~37     ~40
   17    57    >   ASSIGN                                                       !4, ~37
   21    58        FETCH_DIM_R                                          ~42     !0, !3
         59        FETCH_DIM_R                                          ~43     ~42, !7
         60        ASSIGN                                                       !9, ~43
   22    61        TYPE_CHECK                                        2          !9
         62      > JMPZ                                                         ~45, ->65
   23    63    >   QM_ASSIGN                                            ~46     null
         64      > JMP                                                          ->72
   24    65    >   FRAMELESS_ICALL_3                str_replace         ~47     '%2C', ''
         66        OP_DATA                                                      !9
         67        CAST                                              4  ~48     ~47
         68        COALESCE                                             ~49     !5
         69        QM_ASSIGN                                            ~49     0
         70        ADD                                                  ~50     ~48, ~49
         71        QM_ASSIGN                                            ~46     ~50
   22    72    >   ASSIGN                                                       !5, ~46
   27    73        INIT_ARRAY                                           ~53     !7, 'month'
   28    74        ADD_ARRAY_ELEMENT                                    ~53     !4, 'total_now'
   29    75        ADD_ARRAY_ELEMENT                                    ~53     !5, 'total_before'
   26    76        ASSIGN_DIM                                                   !6
   29    77        OP_DATA                                                      ~53
   15    78        PRE_INC                                                      !7
         79    >   IS_SMALLER_OR_EQUAL                                          !7, 12
         80      > JMPNZ                                                        ~55, ->45
   32    81    >   INIT_FCALL                                                   'var_export'
         82        SEND_VAR                                                     !6
         83        DO_ICALL                                                     
         84      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
193.78 ms | 2268 KiB | 17 Q