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(15));
based on 4Ztt5
Output for 5.3.0 - 7.2.0
<pre>Array ( [0] => Array ( [year] => 2014 [month] => 01 [monthName] => Jan ) [1] => Array ( [year] => 2014 [month] => 02 [monthName] => Feb ) [2] => Array ( [year] => 2014 [month] => 03 [monthName] => Mar ) [3] => Array ( [year] => 2014 [month] => 04 [monthName] => Apr ) [4] => Array ( [year] => 2014 [month] => 05 [monthName] => May ) [5] => Array ( [year] => 2014 [month] => 06 [monthName] => Jun ) [6] => Array ( [year] => 2014 [month] => 07 [monthName] => Jul ) [7] => Array ( [year] => 2014 [month] => 08 [monthName] => Aug ) [8] => Array ( [year] => 2014 [month] => 09 [monthName] => Sep ) [9] => Array ( [year] => 2014 [month] => 10 [monthName] => Oct ) [10] => Array ( [year] => 2014 [month] => 11 [monthName] => Nov ) [11] => Array ( [year] => 2014 [month] => 12 [monthName] => Dec ) [12] => Array ( [year] => 2015 [month] => 01 [monthName] => Jan ) [13] => Array ( [year] => 2015 [month] => 02 [monthName] => Feb ) [14] => 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 ) [3] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [4] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [5] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [6] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [7] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [8] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [9] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [10] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [11] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [12] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [13] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) [14] => Array ( [year] => 1970 [month] => 01 [monthName] => Jan ) ) </pre>