3v4l.org

run code in 150+ 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.4.45, 5.6.28, 7.0.14 - 7.1.0
string(14) "Thu 01-01-2015" string(14) "Sun 01-04-2015" string(14) "Thu 01-08-2015" string(14) "Sun 01-11-2015" string(14) "Thu 01-15-2015" string(14) "Sun 01-18-2015"
Output for 5.5.24 - 5.6.21, 7.0.0 - 7.0.6
string(14) "Thu 01-07-2016" string(14) "Sun 01-10-2016" string(14) "Thu 01-14-2016" string(14) "Sun 01-17-2016" string(14) "Thu 01-21-2016" string(14) "Sun 01-24-2016"
Output for hhvm-3.10.0 - 3.12.0
string(14) "Mon 01-25-2016" string(14) "Mon 01-25-2016" string(14) "Mon 01-25-2016" string(14) "Mon 01-25-2016" string(14) "Mon 01-25-2016" string(14) "Mon 01-25-2016"
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.