3v4l.org

run code in 300+ 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 = 34
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/LSQRg
function name:  (null)
number of ops:  39
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, ->34
         13    > > FE_FETCH_R                                       ~13     $12, !3, ->34
         14    >   ASSIGN                                                   !4, ~13
   29    15        INIT_FCALL                                               'strpos'
         16        FETCH_DIM_R                                      ~15     !2, !4
         17        SEND_VAL                                                 ~15
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $16     
         20        TYPE_CHECK                                  1018          $16
         21      > JMPZ                                                     ~17, ->33
         22    >   FETCH_DIM_R                                      ~18     !2, !4
         23        INIT_FCALL                                               'array_sum'
         24        INIT_FCALL                                               'array_slice'
         25        SEND_VAR                                                 !0
         26        SEND_VAR                                                 !4
         27        SEND_VAL                                                 6
         28        DO_ICALL                                         $20     
         29        SEND_VAR                                                 $20
         30        DO_ICALL                                         $21     
         31        ASSIGN_DIM                                               !5, ~18
         32        OP_DATA                                                  $21
   28    33    > > JMP                                                      ->13
         34    >   FE_FREE                                                  $12
   31    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !5
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179 ms | 1400 KiB | 27 Q