3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = array( "date_2019_12" => 0, "date_2019_11" => 0, "date_2019_10" => 0, "date_2019_09" => 0, "date_2019_08" => 0, "date_2019_07" => 0, "date_2019_06" => 0, "date_2019_05" => 0, "date_2019_04" => 0, "date_2019_03" => 0, "date_2019_02" => 0, "date_2019_01" => 10, "date_2018_12" => 1, "date_2018_11" => 2, "date_2018_10" => 3, "date_2018_09" => 4, "date_2018_08" => 5, "date_2018_07" => 6, ); krsort($array); $year = "2019"; $keys = array_keys($array); foreach(array_values($array) as $k => $v){ if(strpos($keys[$k], $year) !== false) $res[$keys[$k]] = array_sum(array_slice($array, $k, 6)); } var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 31
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 31
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 30
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/LSQRg
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array, !1 = $year, !2 = $keys, !3 = $v, !4 = $k, !5 = $res
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   24     1        INIT_FCALL                                                   'krsort'
          2        SEND_REF                                                     !0
          3        DO_ICALL                                                     
   26     4        ASSIGN                                                       !1, '2019'
   27     5        INIT_FCALL                                                   'array_keys'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                             $9      
          8        ASSIGN                                                       !2, $9
   28     9        INIT_FCALL                                                   'array_values'
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                             $11     
         12      > FE_RESET_R                                           $12     $11, ->31
         13    > > FE_FETCH_R                                           ~13     $12, !3, ->31
         14    >   ASSIGN                                                       !4, ~13
   29    15        FETCH_DIM_R                                          ~15     !2, !4
         16        FRAMELESS_ICALL_2                strpos              ~16     ~15, !1
         17        TYPE_CHECK                                      1018          ~16
         18      > JMPZ                                                         ~17, ->30
         19    >   FETCH_DIM_R                                          ~18     !2, !4
         20        INIT_FCALL                                                   'array_sum'
         21        INIT_FCALL                                                   'array_slice'
         22        SEND_VAR                                                     !0
         23        SEND_VAR                                                     !4
         24        SEND_VAL                                                     6
         25        DO_ICALL                                             $20     
         26        SEND_VAR                                                     $20
         27        DO_ICALL                                             $21     
         28        ASSIGN_DIM                                                   !5, ~18
         29        OP_DATA                                                      $21
   28    30    > > JMP                                                          ->13
         31    >   FE_FREE                                                      $12
   31    32        INIT_FCALL                                                   'var_dump'
         33        SEND_VAR                                                     !5
         34        DO_ICALL                                                     
         35      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.32 ms | 2192 KiB | 19 Q