<?php$day = 'saturday';$step = 2;$unit = 'W';$start = new DateTime();$end = clone $start;$start->modify($day); // 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;}
<?php$day = 'saturday';$step = 2;$unit = 'W';$start = new DateTime();$end = clone $start;$start->modify($day); // 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 8.0.13
Parse error: syntax error, unexpected variable "$day" in /in/AO78a on line 1
Process exited with code 255.
Output for 5.4.0 - 5.4.34, 7.3.32 - 7.3.33, 7.4.33
Parse error: syntax error, unexpected '$day' (T_VARIABLE) in /in/AO78a on line 1
Process exited with code 255.