3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getOverlapDays($ranges) { $overlapDays = 0; // no overlap by default $range = $ranges[0]; // starting with the first element of range array $itemsCnt = count($ranges); for ($id = 1; $id < $itemsCnt; $id++) { $start1 = is_a($range["start"], "DateTime") ? $range["start"] : new DateTime($range["start"]); $end1 = is_a($range["end"], "DateTime") ? $range["end"] : new DateTime($range["end"]); $start2 = is_a($ranges[$id]["start"], "DateTime") ? $ranges[$id]["start"] : new DateTime($ranges[$id]["start"]); $end2 = is_a($ranges[$id]["end"], "DateTime") ? $ranges[$id]["end"] : new DateTime($ranges[$id]["end"]); if ($start1 <= $end2 && $end1 >= $start2) { // if the dates overlap return min($end1, $end2)->diff(max($start2, $start1))->days + 1; // return how many days overlap } else { $range = [ "start" => $start1 > $start2 ? $start1 : $start2, "end" => $end1 > $end2 ? $end1 : $end2 ]; } } return $overlapDays; } // example $ranges = array( array('start' => '2013-12-31', 'end' => '2013-12-31'), array('start' => '2014-01-01', 'end' => '2014-01-01') ); echo getOverlapDays($ranges);
Output for git.master, git.master_jit, rfc.property-hooks
0

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:
77.32 ms | 401 KiB | 8 Q