3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getRange($start, $end) { $range = []; $start_date = \DateTime::createFromFormat('Y-m-d H:i:s', $start); $end_date = \DateTime::createFromFormat('Y-m-d H:i:s', $end); $diff = $end_date->diff($start_date); for($i = 0; $i <= $diff->days; $i++) { $event_end = clone $start_date; $event_end->add(new \DateInterval("P1D")); if ($event_end > $end_date) { $range[] = [ $start_date->format('Y-m-d'), $start_date->format('Y-m-d 00:00:00'), $end_date->format('Y-m-d H:i:s'), ]; break; } $range[] = [ $start_date->format('Y-m-d'), $i > 0 ? $start_date->format('Y-m-d 00:00:00') : $start_date->format('Y-m-d H:i:s'), $event_end->format('Y-m-d 00:00:00') ]; $start_date->add(new \DateInterval("P1D")); } return $range; } echo "Example 1: ", json_encode(getRange('2010-11-07 10:00:00', '2010-11-09 19:00:00'), JSON_PRETTY_PRINT); echo "\nExample 2: ", json_encode(getRange('2010-11-01 15:00:00', '2010-11-02 16:00:00'), JSON_PRETTY_PRINT); echo "\nExample 3: ", json_encode(getRange('2009-12-30 18:00:00', '2010-01-02 02:00:00'), JSON_PRETTY_PRINT);
Output for git.master, git.master_jit, rfc.property-hooks
Example 1: [ [ "2010-11-07", "2010-11-07 10:00:00", "2010-11-08 00:00:00" ], [ "2010-11-08", "2010-11-08 00:00:00", "2010-11-09 00:00:00" ], [ "2010-11-09", "2010-11-09 00:00:00", "2010-11-09 19:00:00" ] ] Example 2: [ [ "2010-11-01", "2010-11-01 15:00:00", "2010-11-02 00:00:00" ], [ "2010-11-02", "2010-11-02 00:00:00", "2010-11-02 16:00:00" ] ] Example 3: [ [ "2009-12-30", "2009-12-30 18:00:00", "2009-12-31 00:00:00" ], [ "2009-12-31", "2009-12-31 00:00:00", "2010-01-01 00:00:00" ], [ "2010-01-01", "2010-01-01 00:00:00", "2010-01-02 02:00:00" ] ]

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
29.51 ms | 407 KiB | 5 Q