So I loop through using for to list out months from current going back 11 months using this
$dateFormat = 'Y-m';
$currentMonth = date($dateFormat);
$monthsToGoBack = 11;
$months = array($currentMonth);
for($m = 1;$m<=$monthsToGoBack;$m++){
$months[] = date($dateFormat, strtotime("-".$m." Months"));
echo $m.'<br>';
}
The strangest thing is happening when I run the script This is how the array is build there is no February but double for March. Does any one have any idea what is causing this.
Array
(
[0] => 2014-10
[1] => 2014-09
[2] => 2014-08
[3] => 2014-07
[4] => 2014-06
[5] => 2014-05
[6] => 2014-04
[7] => 2014-03
[8] => 2014-03
[9] => 2014-01
[10] => 2013-12
[11] => 2013-11
)
ANSWER TO PROBLEM
for($m = 1;$m<=$monthsToGoBack;$m++){
$months[] = date($dateFormat,strtotime(date('Y-m') . '-01 -'.$m.' months'));
}