3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getPlayDays($startWeek, $numWeeks) { $numWeeks --; $result = []; $currYear = (int)(new \DateTime())->format('Y'); $oneDay = new \DateInterval('P1D'); // Start on the first Thursday of the given week. $startDate = (new \DateTime())->setISODate($currYear, $startWeek, 4); $endDate = clone $startDate; $endDate->add(new \DateInterval("P{$numWeeks}W")); // End on the Sunday of the last week. $endDate->setISODate((int)$endDate->format('o'), (int)$endDate->format('W'), 7); $period = new \DatePeriod($startDate, $oneDay, $endDate->add($oneDay)); foreach($period as $day){ if(4 === (int)$day->format('N') || 7 === (int)$day->format('N') ){ $result[] = $day; } } return $result; } foreach(getPlayDays(1, 3) as $playDay){ var_dump($playDay->format('D m-d-Y')); }
Output for 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.34, 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.6
string(14) "Thu 01-06-2022" string(14) "Sun 01-09-2022" string(14) "Thu 01-13-2022" string(14) "Sun 01-16-2022" string(14) "Thu 01-20-2022" string(14) "Sun 01-23-2022"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/P9VHA on line 5
Process exited with code 255.

preferences:
248.66 ms | 401 KiB | 415 Q