3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = strtotime('20016-02-05'); $end = strtotime('2016-04-05'); $start_m = new DateTime('20016-02-05'); $end_m = new DateTime('2016-04-05'); $start_m->modify('first day of this month'); $end_m->modify('first day of next month'); $interval = DateInterval::createFromDateString('1 month'); $period = new DatePeriod($start_m, $interval, $end_m); foreach ($period as $dt) { $date_range_m[]=$dt->format("Y-m"); } print_r($date_range_m);

preferences:
46.97 ms | 402 KiB | 5 Q