3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = (new DateTime('1 year ago'))->modify('first 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'); } $reverse_months = array_reverse($months); print_r($reverse_months);

preferences:
42.57 ms | 402 KiB | 5 Q