Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Created May 22, 2014 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudiedirkx/c13b7625a3decf5743e6 to your computer and use it in GitHub Desktop.
Save rudiedirkx/c13b7625a3decf5743e6 to your computer and use it in GitHub Desktop.
<?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