3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); ini_set('display_errors', 1); date_default_timezone_set('UTC'); //to be sure that DateInterval will work as intended $fist_day_of_the_month = (new DateTime)->format('Y-m-01'); $range = new DatePeriod( new DateTime($fist_day_of_the_month), //begin new DateInterval('P1M'), //interval new DateTime($fist_day_of_the_month.' +24 month') //end ); foreach ($range as $date) { echo $date->format('Y-m-d'), PHP_EOL; }

preferences:
35.61 ms | 402 KiB | 5 Q