- print_r: documentation ( source)
- date: documentation ( source)
- strtotime: documentation ( source)
<?php
function _getRollingMonths($months = 12) {
$currentTime = strtotime('2015-03-01');
$dates = array();
for($i=$months-1;$i>=0;$i--) {
$dates[] = array(
'year' => date('Y', strtotime("first day of -$i months", $currentTime)),
'month' => date('m', strtotime("first day of -$i months", $currentTime)),
'monthName' => date('M', strtotime("first day of -$i months", $currentTime))
);
}
return $dates;
}
function debug($var) {
echo "<pre>";
print_r($var);
echo "</pre>";
}
debug(_getRollingMonths(15));