So here is an interesting problem I learned today.
I need to populate an array with the last 12 months, starting with the past month. So in August 2011, the last 12
It's because not every month has a 31st. So strtotime() is advancing to the next month. i.e. 4/31 = 5/1.
You'd be better off using mktime() for this as it's dumber than strtotime().
To take advantage of a smart function like strtotime() and avoid tracking the year for mktime(), the following is my suggestion:
$month = time();
for ($i = 1; $i <= 12; $i++) {
$month = strtotime('last month', $month);
$months[] = date("r", $month);
}
print_r($months);
Adjust logic and optimize as you see fit.