3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait TimeRestriction{ public function excludeTimes($times, $restrictions) { $timeList = $this->mergeTimes($times, $restrictions); var_dump($timeList); $validTimes = []; $result = []; foreach ($timeList as $key => $time) { $restrictionInclusive = false; if ($key == count($timeList) - 1) { $restrictionInclusive = true; } if ($this->isTimeWithinRanges($time, $times) && !$this->isTimeWithinRanges($time, $restrictions, $restrictionInclusive)) { $validTimes[] = $time; } } $validItemsCount = count($validTimes); for ($i = 0; $i < $validItemsCount; $i += 2) { $result[] = [ 'start_time' => $validTimes[$i], 'end_time' => $validTimes[$i + 1] ]; } return $result; } public function isTimeWithinRanges($time, $ranges, $inclusive = true) { foreach ($ranges as $range) { if ($this->isTimeWithinRange($time, $range, $inclusive)) { return true; } } return false; } public function isTimeWithinRange($time, $range, $inclusive = true) { if ($inclusive) { return $time->gte($range['start_time']) && $time->lte($range['end_time']); } else { return $time->gt($range['start_time']) && $time->lt($range['end_time']); } } public function mergeTimes() { $allTimes = collect([]); $params = func_get_args(); foreach ($params as $param) { foreach ($param as $timeRange) { $allTimes->push($timeRange['start_time']); $allTimes->push($timeRange['end_time']); } } var_dump($allTimes->toArray()); return $allTimes->sortBy(function (Carbon $value, $key) { return $value->getTimestamp(); })->values()->unique(function (Carbon $value) { return $value->getTimestamp(); })->all(); } }
Output for git.master, git.master_jit, rfc.property-hooks

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:
35.84 ms | 405 KiB | 5 Q