3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates = [ '2010-12-30', '2011-01-01', '2011-01-02', '2011-01-03', '2011-01-06', '2011-01-06', '2011-01-07', '2011-01-10', ]; function formatRange(object $start, ?object $end = null): string { $last = $end ?? $start; return sprintf( '%s%s', $start->format('l j M'), $last === $start ? '' : ' to ' . $last->format('l j M') ); } $result = []; foreach ($dates as $date) { $obj = new Datetime($date); if (isset($temp['start'])) { if ($obj->diff($temp['end'] ?? $temp['start'])->days > 1) { $result[] = formatRange(...$temp); $temp = ['start' => $obj]; } else { $temp['end'] = $obj; } } else { $temp['start'] = $obj; } } if (isset($temp)) { $result[] = formatRange(...$temp); } var_export($result);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
array ( 0 => 'Thursday 30 Dec', 1 => 'Saturday 1 Jan to Monday 3 Jan', 2 => 'Thursday 6 Jan to Friday 7 Jan', 3 => 'Monday 10 Jan', )
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:
123.05 ms | 407 KiB | 5 Q