3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $start = (new DateTime('1 year ago'))->modify('last day of this month'); $end = (new DateTime())->modify('first day of this month'); $interval = new DateInterval('P1M'); $period = new DatePeriod($start, $interval, $end); $months = array(); foreach ($period as $dt) { $months[$dt->format('Y-m-d')] = $dt->format('Y-m'); } $reverse_months = array_reverse($months); print_r($reverse_months);
based on Qt1hW
Output for 5.4.0 - 5.4.45, 5.6.28, 7.0.20 - 7.2.0
Array ( [2015-09-01] => 2015-09 [2015-08-01] => 2015-08 [2015-07-01] => 2015-07 [2015-06-01] => 2015-06 [2015-05-01] => 2015-05 [2015-04-01] => 2015-04 [2015-03-01] => 2015-03 [2015-02-01] => 2015-02 [2015-01-01] => 2015-01 [2014-12-01] => 2014-12 [2014-10-31] => 2014-10 )
Output for 5.5.35 - 5.6.7, 5.6.21, 7.0.6
Array ( [2016-04-01] => 2016-04 [2016-03-01] => 2016-03 [2016-02-01] => 2016-02 [2016-01-01] => 2016-01 [2015-12-01] => 2015-12 [2015-11-01] => 2015-11 [2015-10-01] => 2015-10 [2015-09-01] => 2015-09 [2015-08-01] => 2015-08 [2015-07-01] => 2015-07 [2015-05-31] => 2015-05 )
Output for 5.5.24 - 5.5.29, 5.5.34, 5.6.8 - 5.6.14, 5.6.20, 7.0.5
Array ( [2016-03-01] => 2016-03 [2016-01-30] => 2016-01 [2015-12-30] => 2015-12 [2015-11-30] => 2015-11 [2015-10-30] => 2015-10 [2015-09-30] => 2015-09 [2015-08-30] => 2015-08 [2015-07-30] => 2015-07 [2015-06-30] => 2015-06 [2015-05-30] => 2015-05 [2015-04-30] => 2015-04 )
Output for 5.5.30 - 5.5.33, 5.6.15 - 5.6.19, 7.0.0 - 7.0.4
Array ( [2016-02-01] => 2016-02 [2016-01-01] => 2016-01 [2015-12-01] => 2015-12 [2015-11-01] => 2015-11 [2015-10-01] => 2015-10 [2015-09-01] => 2015-09 [2015-08-01] => 2015-08 [2015-07-01] => 2015-07 [2015-06-01] => 2015-06 [2015-05-01] => 2015-05 [2015-03-31] => 2015-03 )
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/empEv on line 2
Process exited with code 255.