3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start_date = new DateTime('2019-01-01'); $end_date = new DateTime('2019-12-31'); $dt = clone $start_date; $dt->modify('last day of previous month')->modify('+2 Sundays'); while ($dt <= $end_date) { if ($dt >= $start_date) $result[] = $dt->format('Y-m-d'); $dt->modify('last day of this month')->modify('+2 Sundays'); } print_r ($result);
Output for 7.1.25 - 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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Array ( [0] => 2019-01-13 [1] => 2019-02-10 [2] => 2019-03-10 [3] => 2019-04-07 [4] => 2019-05-12 [5] => 2019-06-09 [6] => 2019-07-07 [7] => 2019-08-11 [8] => 2019-09-08 [9] => 2019-10-13 [10] => 2019-11-10 [11] => 2019-12-08 )

preferences:
93.91 ms | 1545 KiB | 4 Q