I have an array with some values. Here I need to make a calculation for Year 2019 only.

```
$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);
```

From this array, I need to calculate the sum of previous five months & current month starting "date_2019_01".

That means I need final array result like below:

```
"date_2019_01" => 25(10+1+2+3+4+5)
"date_2019_02" => 20(0+10+1+2+3+4)
"date_2019_03" => 16(0+0+10+1+2+3)
"date_2019_04" => 13(0+0+0+10+1+2)
... until "date_2019-12".
```

I have spend many times finding solution but I could not. Can anybody help me?

I have tried following code and somewhere now I am lost.

```
$newArr = array();
foreach($array as $key => $val) {
$explode = explode("_", $key);
$value = (int)$explode[2];
for($i = 0; $i <= 5; $i++) {
$newArr[$array[$explode[0].'_'.$explode[1].'_'.$value]] = $array[$explode[0].'_'.$explode[1].'_'.$value];
$value--;
}
}
```