3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_list= 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_keys($array_list) as $key){ $years[] = explode(" ", $key)[1]; } foreach(array_unique($years) as $year){ $res[$year] = array_sum(array_intersect_key(array_values($array_list), array_intersect($years, [$year]))); } var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 38
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 38
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 14
filename:       /in/kCBRE
function name:  (null)
number of ops:  43
compiled vars:  !0 = $array_list, !1 = $key, !2 = $years, !3 = $year, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $6      
          4      > FE_RESET_R                                       $7      $6, ->14
          5    > > FE_FETCH_R                                               $7, !1, ->14
    6     6    >   INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '+'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $9      
         10        FETCH_DIM_R                                      ~10     $9, 1
         11        ASSIGN_DIM                                               !2
         12        OP_DATA                                                  ~10
    5    13      > JMP                                                      ->5
         14    >   FE_FREE                                                  $7
    9    15        INIT_FCALL                                               'array_unique'
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $11     
         18      > FE_RESET_R                                       $12     $11, ->38
         19    > > FE_FETCH_R                                               $12, !3, ->38
   10    20    >   INIT_FCALL                                               'array_sum'
         21        INIT_FCALL                                               'array_intersect_key'
         22        INIT_FCALL                                               'array_values'
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $14     
         25        SEND_VAR                                                 $14
         26        INIT_FCALL                                               'array_intersect'
         27        SEND_VAR                                                 !2
         28        INIT_ARRAY                                       ~15     !3
         29        SEND_VAL                                                 ~15
         30        DO_ICALL                                         $16     
         31        SEND_VAR                                                 $16
         32        DO_ICALL                                         $17     
         33        SEND_VAR                                                 $17
         34        DO_ICALL                                         $18     
         35        ASSIGN_DIM                                               !4, !3
         36        OP_DATA                                                  $18
    9    37      > JMP                                                      ->19
         38    >   FE_FREE                                                  $12
   13    39        INIT_FCALL                                               'var_dump'
         40        SEND_VAR                                                 !4
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.74 ms | 1010 KiB | 21 Q