3v4l.org

run code in 300+ PHP versions simultaneously
<?php function countDaysByName($dayName, \DateTime $start, \DateTime $end) { $count = 0; $interval = new \DateInterval('P1D'); $period = new \DatePeriod($start, $interval, $end); foreach($period as $day){ if($day->format('D') === ucfirst(substr($dayName, 0, 3))){ $count ++; } } return $count; } echo countDaysByName('wednesday', new \DateTime(2016-01-18), new \DateTime(2016-01-23)); echo var_dump(new \DateTime(2016-01-18));

preferences:
55.47 ms | 402 KiB | 5 Q