3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dow = 'saturday'; $step = 2; $unit = 'W'; $start = new DateTime(); $end = clone $start; $start->modify($dow); // Move to first occurence $end->add(new DateInterval('P1Y')); // Move to 1 year from start $interval = new DateInterval("P{$step}{$unit}"); $period = new DatePeriod($start, $interval, $end); foreach ($period as $date) { echo $date->format('D, d M Y, H:m:s'), PHP_EOL; }
Output for 5.3.6 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Sat, 01 Nov 2014, 00:11:00 Sat, 15 Nov 2014, 00:11:00 Sat, 29 Nov 2014, 00:11:00 Sat, 13 Dec 2014, 00:12:00 Sat, 27 Dec 2014, 00:12:00 Sat, 10 Jan 2015, 00:01:00 Sat, 24 Jan 2015, 00:01:00 Sat, 07 Feb 2015, 00:02:00 Sat, 21 Feb 2015, 00:02:00 Sat, 07 Mar 2015, 00:03:00 Sat, 21 Mar 2015, 00:03:00 Sat, 04 Apr 2015, 00:04:00 Sat, 18 Apr 2015, 00:04:00 Sat, 02 May 2015, 00:05:00 Sat, 16 May 2015, 00:05:00 Sat, 30 May 2015, 00:05:00 Sat, 13 Jun 2015, 00:06:00 Sat, 27 Jun 2015, 00:06:00 Sat, 11 Jul 2015, 00:07:00 Sat, 25 Jul 2015, 00:07:00 Sat, 08 Aug 2015, 00:08:00 Sat, 22 Aug 2015, 00:08:00 Sat, 05 Sep 2015, 00:09:00 Sat, 19 Sep 2015, 00:09:00 Sat, 03 Oct 2015, 00:10:00 Sat, 17 Oct 2015, 00:10:00 Sat, 31 Oct 2015, 00:10:00
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 Sat, 01 Nov 2014, 00:11:00 Sat, 15 Nov 2014, 00:11:00 Sat, 29 Nov 2014, 00:11:00 Sat, 13 Dec 2014, 00:12:00 Sat, 27 Dec 2014, 00:12:00 Sat, 10 Jan 2015, 00:01:00 Sat, 24 Jan 2015, 00:01:00 Sat, 07 Feb 2015, 00:02:00 Sat, 21 Feb 2015, 00:02:00 Sat, 07 Mar 2015, 00:03:00 Sat, 21 Mar 2015, 00:03:00 Sat, 04 Apr 2015, 00:04:00 Sat, 18 Apr 2015, 00:04:00 Sat, 02 May 2015, 00:05:00 Sat, 16 May 2015, 00:05:00 Sat, 30 May 2015, 00:05:00 Sat, 13 Jun 2015, 00:06:00 Sat, 27 Jun 2015, 00:06:00 Sat, 11 Jul 2015, 00:07:00 Sat, 25 Jul 2015, 00:07:00 Sat, 08 Aug 2015, 00:08:00 Sat, 22 Aug 2015, 00:08:00 Sat, 05 Sep 2015, 00:09:00 Sat, 19 Sep 2015, 00:09:00 Sat, 03 Oct 2015, 00:10:00 Sat, 17 Oct 2015, 00:10:00 Sat, 31 Oct 2015, 00:10:00
Output for 5.3.0 - 5.3.5
Sat, 01 Nov 2014, 11:11:32 Sat, 15 Nov 2014, 11:11:32 Sat, 29 Nov 2014, 11:11:32 Sat, 13 Dec 2014, 11:12:32 Sat, 27 Dec 2014, 11:12:32 Sat, 10 Jan 2015, 11:01:32 Sat, 24 Jan 2015, 11:01:32 Sat, 07 Feb 2015, 11:02:32 Sat, 21 Feb 2015, 11:02:32 Sat, 07 Mar 2015, 11:03:32 Sat, 21 Mar 2015, 11:03:32 Sat, 04 Apr 2015, 11:04:32 Sat, 18 Apr 2015, 11:04:32 Sat, 02 May 2015, 11:05:32 Sat, 16 May 2015, 11:05:32 Sat, 30 May 2015, 11:05:32 Sat, 13 Jun 2015, 11:06:32 Sat, 27 Jun 2015, 11:06:32 Sat, 11 Jul 2015, 11:07:32 Sat, 25 Jul 2015, 11:07:32 Sat, 08 Aug 2015, 11:08:32 Sat, 22 Aug 2015, 11:08:32 Sat, 05 Sep 2015, 11:09:32 Sat, 19 Sep 2015, 11:09:32 Sat, 03 Oct 2015, 11:10:32 Sat, 17 Oct 2015, 11:10:32
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::add() in /in/JqQgM on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/JqQgM on line 6
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_VARIABLE in /in/JqQgM on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_VARIABLE in /in/JqQgM on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/JqQgM on line 7
Process exited with code 255.

preferences:
295.69 ms | 401 KiB | 458 Q