I was able to get it working with DateTime()
. By starting with the end date I was starting with the first of the month. That made the number of days in each month irrelevant. Then all I had to do was reverse the array of dates to have it meet your desired format.
$start = new DateTime('2011-09-01');
$end = new DateTime();
$interval = new DateInterval('P1M');
$period = new DatePeriod($start, $interval, $end);
$months= array();
foreach ($period as $dt) {
$months[] = $dt->format('F Y');
}
$months = array_reverse($months);
echo implode('<br>', $months);