3v4l.org

run code in 300+ PHP versions simultaneously
<?php function _getRollingMonths($months = 12) { $currentTime = strtotime('2015-01-30'); $dates = array(); for($i=$months-1;$i>=0;$i--) { $dates[] = array( 'year' => date('Y', strtotime("first day of -$i months", $currentTime)), 'month' => date('m', strtotime("first day of -$i months", $currentTime)), 'monthName' => date('M', strtotime("first day of -$i months", $currentTime)) ); } return $dates; } function _getMonths($year = null) { if (!isset($year)) { $year = date('Y'); } $dates = array(); for($month=1;$month<=12;$month++) { $dates[] = array( 'year' => date('Y', strtotime("$year-$month-01")), 'month' => date('m', strtotime("$year-$month-01")), 'monthName' => date('M', strtotime("$year-$month-01")) ); } return $dates; } function _getYTDMonths($year = null) { if (!isset($year)) { $year = date('Y'); } $dates = array(); for($i=date('m')-1;$i>=0;$i--) { $dates[] = array( 'year' => $year, 'month' => date('m', strtotime("first day of -$i months")), 'monthName' => date('M', strtotime("first day of -$i months")) ); if (date('m', strtotime("-$i months")) == date('m')) { $dates[count($dates)-1]['day'] = date('d', strtotime("-$i months")); } } return $dates; } function debug($var) { echo "<pre>"; print_r($var); echo "</pre>"; } debug(date('Y-m-d H:i:s', strtotime('-1 second', strtotime('+1 month', strtotime('2015-01-01 00:00:00')))));

preferences:
33.12 ms | 402 KiB | 5 Q