3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getIntervals($start_date, $end_date, $period) { $period_formats = array( 'day' => 'Y-m-d', 'week' => 'Y-W', 'month' => 'Y-m', 'year' => 'Y' ); $start = new DateTime($start_date); if($period != 'day') { $start->modify('first day of this '.$period); } $end = new DateTime($end_date); if($period != 'day') { $end->modify('first day of next '.$period); } $interval = DateInterval::createFromDateString('1 '.$period); $period = new DatePeriod($start, $interval, $end); foreach ($period as $dt) { echo $dt->format($period_formats[$period]) . "<br>\n"; } } getIntervals('2014-06-01', '2014-10-18', 'day'); ?>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br> Warning: Illegal offset type in /in/uUAFP on line 21 <br>
Output for hhvm-3.12.0
Warning: Invalid operand type was used: Invalid type used as key in /in/uUAFP on line 21 Catchable fatal error: Object of class DatePeriod could not be converted to string in /in/uUAFP on line 21
Process exited with code 255.
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.2.0 - 5.2.17
Fatal error: Class 'DateInterval' not found in /in/uUAFP on line 17
Process exited with code 255.
Output for 5.0.0 - 5.1.6
Fatal error: Class 'DateTime' not found in /in/uUAFP on line 9
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: datetime in /in/uUAFP on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: datetime in /in/uUAFP on line 9