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 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
189.47 ms | 407 KiB | 5 Q