3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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.6.30, 7.0.0 - 7.2.0
string(14) "Thu 01-04-2018" string(14) "Sun 01-07-2018" string(14) "Thu 01-11-2018" string(14) "Sun 01-14-2018" string(14) "Thu 01-18-2018" string(14) "Sun 01-21-2018"
Output for hhvm-3.10.1 - 3.22.0
string(14) "Mon 01-22-2018" string(14) "Mon 01-22-2018" string(14) "Mon 01-22-2018" string(14) "Mon 01-22-2018" string(14) "Mon 01-22-2018" string(14) "Mon 01-22-2018"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/P9VHA on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/P9VHA on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/P9VHA on line 5
Process exited with code 255.