3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = (new DateTime('2017-01-01'))->modify('first day of this month'); $end = (new DateTime('2018-03-04'))->modify('first day of this month'); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start, $interval, $end); $months = array(); foreach ($period as $dt) { $months[] = $dt->format("F Y"); } print_r($months);

preferences:
47.16 ms | 402 KiB | 5 Q