3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dow = 'saturday'; $step = 2; $unit = 'W'; $start = new DateTime('2012-06-02'); $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'), PHP_EOL; }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 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.7
Sat, 02 Jun 2012 Sat, 16 Jun 2012 Sat, 30 Jun 2012 Sat, 14 Jul 2012 Sat, 28 Jul 2012 Sat, 11 Aug 2012 Sat, 25 Aug 2012 Sat, 08 Sep 2012 Sat, 22 Sep 2012 Sat, 06 Oct 2012 Sat, 20 Oct 2012 Sat, 03 Nov 2012 Sat, 17 Nov 2012 Sat, 01 Dec 2012 Sat, 15 Dec 2012 Sat, 29 Dec 2012 Sat, 12 Jan 2013 Sat, 26 Jan 2013 Sat, 09 Feb 2013 Sat, 23 Feb 2013 Sat, 09 Mar 2013 Sat, 23 Mar 2013 Sat, 06 Apr 2013 Sat, 20 Apr 2013 Sat, 04 May 2013 Sat, 18 May 2013 Sat, 01 Jun 2013
Output for 5.2.0 - 5.2.17
Fatal error: Call to undefined method DateTime::add() in /in/2PATk 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/2PATk 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/2PATk 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/2PATk on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/2PATk on line 7
Process exited with code 255.

preferences:
200.13 ms | 401 KiB | 312 Q