3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = new DateTime('2012-01-01'); $start->modify('first day of this month'); $end = new DateTime(); $end->modify('last day of next month'); $interval = DateInterval::createFromDateString('4 month'); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { // echo $dt->format("Y-m-d") . PHP_EOL; $date[$dt->format("Y")][] = $dt->format("Y-m-d"); } print_r($date);
Output for 5.4.2 - 5.4.45, 5.6.28, 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Array ( [2012] => Array ( [0] => 2012-01-01 [1] => 2012-05-01 [2] => 2012-09-01 ) [2013] => Array ( [0] => 2013-01-01 [1] => 2013-05-01 [2] => 2013-09-01 ) [2014] => Array ( [0] => 2014-01-01 [1] => 2014-05-01 [2] => 2014-09-01 ) [2015] => Array ( [0] => 2015-01-01 [1] => 2015-05-01 [2] => 2015-09-01 ) )
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Array ( [2012] => Array ( [0] => 2012-01-01 [1] => 2012-05-01 [2] => 2012-09-01 ) [2013] => Array ( [0] => 2013-01-01 [1] => 2013-05-01 [2] => 2013-09-01 ) [2014] => Array ( [0] => 2014-01-01 [1] => 2014-05-01 [2] => 2014-09-01 ) [2015] => Array ( [0] => 2015-01-01 [1] => 2015-05-01 [2] => 2015-09-01 ) )
Output for 5.5.24 - 5.5.29, 5.5.34 - 5.5.35, 5.6.7 - 5.6.14, 5.6.20 - 5.6.21, 7.0.5 - 7.0.6
Array ( [2012] => Array ( [0] => 2012-01-01 [1] => 2012-05-01 [2] => 2012-09-01 ) [2013] => Array ( [0] => 2013-01-01 [1] => 2013-05-01 [2] => 2013-09-01 ) [2014] => Array ( [0] => 2014-01-01 [1] => 2014-05-01 [2] => 2014-09-01 ) [2015] => Array ( [0] => 2015-01-01 [1] => 2015-05-01 [2] => 2015-09-01 ) [2016] => Array ( [0] => 2016-01-01 [1] => 2016-05-01 ) )
Output for 5.5.30 - 5.5.33, 5.6.15 - 5.6.19, 7.0.0 - 7.0.4
Array ( [2012] => Array ( [0] => 2012-01-01 [1] => 2012-05-01 [2] => 2012-09-01 ) [2013] => Array ( [0] => 2013-01-01 [1] => 2013-05-01 [2] => 2013-09-01 ) [2014] => Array ( [0] => 2014-01-01 [1] => 2014-05-01 [2] => 2014-09-01 ) [2015] => Array ( [0] => 2015-01-01 [1] => 2015-05-01 [2] => 2015-09-01 ) [2016] => Array ( [0] => 2016-01-01 ) )

preferences:
253.81 ms | 403 KiB | 242 Q