3v4l.org

run code in 300+ PHP versions simultaneously
<?php $properties_no = ['1021-5150', '1021-5152', '1021-5153', '1021-5154', '1021-5156', '1021-5157', '1021-5158', '1021-5159', '1021-5161', '1021-5162', '1021-5163']; final class Range { private string $from; private string $to; public function __construct(string $from, string $to) { $this->from = $from; $this->to = $to; } public function __toString(): string { return $this->from === $this->to ? $this->from : "{$this->from} to {$this->to}"; } } /** * @param string[] $values * @return Range[] */ function computeRanges(array $values): array { if (count($values) === 0) { return []; } $ranges = []; $first = $previous = $values[0]; $previousIntValue = (int)str_replace('-', '', $first); foreach (array_slice($values, 1) as $value) { $intValue = (int)str_replace('-', '', $value); if ($intValue > $previousIntValue + 1) { $ranges[] = new Range($first, $previous); $first = $value; } $previous = $value; $previousIntValue = $intValue; } $ranges[] = new Range($first, $previous); return $ranges; } echo implode(PHP_EOL, computeRanges($properties_no));
Output for git.master, git.master_jit, rfc.property-hooks
1021-5150 1021-5152 to 1021-5154 1021-5156 to 1021-5159 1021-5161 to 1021-5163

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.8 ms | 1510 KiB | 4 Q