3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function _getRollingMonths($months = 12) { $dates = array(); for($i=$months-1;$i>=0;$i--) { $dates[] = array( 'year' => date('Y', strtotime("first day of -$i months")), 'month' => date('m', strtotime("first day of -$i months")), 'monthName' => date('M', strtotime("first day of -$i months")) ); } return $dates; } function debug($var) { echo "<pre>"; print_r($var); echo "</pre>"; } debug(_getRollingMonths(3));
based on XK2qU
Output for 5.3.0 - 7.2.0
<pre>Array ( [0] => Array ( [year] => 2015 [month] => 01 [monthName] => Jan ) [1] => Array ( [year] => 2015 [month] => 02 [monthName] => Feb ) [2] => Array ( [year] => 2015 [month] => 03 [monthName] => Mar ) ) </pre>
Output for 4.3.0 - 5.2.17
<pre>Array ( [0] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [1] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [2] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) ) </pre>