Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
$years = array_reverse(range(date('Y')-5, date('Y')));
$years = array_reduce(range(0, 60), function($months, $offset) {
$utc = strtotime('-' . $offset . ' months');
$offset % date('n') == 0 and $months += array(date('Y', $utc) => date('Y', $utc));
$months += array(date('Y-m', $utc) => strtolower(date('Y - M', $utc)));
return $months;
}, array());
/* Output:
Array
(
[2014] => 2014
[2014-05] => 2014 - may
[2014-04] => 2014 - apr
[2014-03] => 2014 - mar
[2014-02] => 2014 - feb
[2014-01] => 2014 - jan
[2013] => 2013
[2013-12] => 2013 - dec
[2013-11] => 2013 - nov
[2013-10] => 2013 - oct
[2013-09] => 2013 - sep
[2013-08] => 2013 - aug
[2013-07] => 2013 - jul
[2013-06] => 2013 - jun
[2013-05] => 2013 - may
[2013-04] => 2013 - apr
[2013-03] => 2013 - mar
... etc
)
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.