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(7 === (int)$day->format('N') ){ $result[] = $day; } } return $result; } foreach(getPlayDays(1, 3) as $playDay){ var_dump($playDay->format('D m-d-Y')); }
based on P9VHA
Output for 5.4.0 - 5.4.34, 5.6.28, 7.0.14 - 7.1.0
string(14) "Sun 01-05-2014" string(14) "Sun 01-12-2014" string(14) "Sun 01-19-2014"
Output for 5.5.24 - 5.6.21, 7.0.0 - 7.0.6
string(14) "Sun 01-10-2016" string(14) "Sun 01-17-2016" string(14) "Sun 01-24-2016"
Output for 5.4.35 - 5.4.45
string(14) "Sun 01-04-2015" string(14) "Sun 01-11-2015" string(14) "Sun 01-18-2015"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/hQ0B7 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/hQ0B7 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/hQ0B7 on line 5
Process exited with code 255.