3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fillDateRange($a, $b, $x = 0, $dates = []) { while (end($dates) != $b && $x = array_push($dates, date("Y-m-d", strtotime("$a +$x day")))); return $dates; } $booked = [ '2017-02-03', '2017-02-24', '2017-04-01', '2017-04-02', '2017-04-03', '2017-04-04', '2017-04-05', '2017-04-06', '2017-04-07', '2017-04-08', '2017-04-09', '2017-04-10', '2017-04-11', '2017-04-12', '2017-04-13', '2017-04-14', '2017-04-15', '2017-04-16', '2017-04-17', '2017-04-18', '2017-04-19', '2017-04-20', '2017-04-21', '2017-04-22', '2017-04-23', '2017-04-24', '2017-04-25', '2017-04-26', '2017-04-27', '2017-04-28', '2017-04-29', '2017-04-30' ]; $search = fillDateRange('2017-02-15', '2017-05-07'); // pre-validated user input // remove all dates from $search where exist in $booked... $vacant = array_diff($search, $booked); // group consecutive days $date_checker = date("Y-m-d", strtotime("{$vacant[0]} -1 day")); $x = 0; foreach ($vacant as $date) { if ($date != date("Y-m-d", strtotime("$date_checker +1 day"))) { ++$x; } $grouped[$x][] = $date; $date_checker = $date; } echo "Array of vacant date ranges:\n"; foreach ($grouped as $group) { $vacant_ranges[] = current($group) . " to " . end($group); } echo "<pre>"; var_export($vacant_ranges); echo "</pre>"; //echo "Array of arrays containing consecutive days:\n"; /*foreach ($grouped as $group) { $vacant_arrays[current($group) . " to " . end($group)] = $group; } echo "<pre>"; var_export($vacant_arrays); echo "</pre>";*/
Output for rfc.property-hooks, git.master_jit, git.master
Array of vacant date ranges: <pre>array ( 0 => '2017-02-15 to 2017-02-23', 1 => '2017-02-25 to 2017-03-31', 2 => '2017-05-01 to 2017-05-07', )</pre>

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:
41 ms | 1136 KiB | 4 Q