Monday, February 8, 2010

Twelve month historical reference (month/year) (rolling)

<?php
$m = date('m');
$y = date('Y');
for ($i = 1; $i < 12; ++$i) {
    $d[] = date($format, mktime(12, 12, 12, $m-$i, 1, $y));
}
$d = array_reverse($d);
array_unshift($d, date($format));
/*
WHEN YOU PARSE THE ARRAY YOULL GET A LISTING OF MONTHS (JAN-DEC)
WHERE BY THE CURRENT MONTH BACK TO JAN ARE OF THE CURRENT YEAR
AND WHEREBY THE NEXT MONTH TO DEC ARE OF THE PREVIOUS YEAR
E.G
TODAY: JAN 2010
OUTPUT:
Month=1&Year=2010
Month=2&Year=2009
Month=3&Year=2009
Month=4&Year=2009
Month=5&Year=2009
Month=6&Year=2009
Month=7&Year=2009
Month=8&Year=2009
Month=9&Year=2009
Month=10&Year=2009
Month=11&Year=2009
Month=12&Year=2009

E.G 
TODAY: NOV 2010
OUTPUT:
Month=11&Year=2010
Month=12&Year=2009
Month=1&Year=2010
Month=2&Year=2010
Month=3&Year=2010
Month=4&Year=2010
Month=5&Year=2010
Month=6&Year=2010
Month=7&Year=2010
Month=8&Year=2010
Month=9&Year=2010
Month=10&Year=2010
*/
?>