3v4l.org

run code in 300+ PHP versions simultaneously
<?php function rangify(array $dates): string { $lastYm = null; $lastN = null; $result = []; foreach ($dates as $date) { $dt = new DateTime($date); $ym = $dt->format('Y-m'); $j = (int) $dt->format('j'); if ($ym === $lastYm) { if (($j - 1) === $lastN) { $ref = preg_replace('/-\d+$/', '', $ref) . "-$j"; } else { $ref .= ",$j"; } } else { unset($ref); $ref = $dt->format('M') . " $j"; $result[] = &$ref; } $lastYm = $ym; $lastN = $j; } return implode(', ', $result); } $tests = [ ['2015-10-27', '2015-10-28', '2015-10-30', '2015-10-31', '2015-11-01'], ['2015-10-31', '2015-11-01', '2015-11-02'], ['2015-10-26', '2015-10-28', '2015-10-29', '2015-10-31', '2015-11-01'], ]; //Oct 30-31, Nov 01 //Oct 31, Nov 1-2 //Oct 29,31, Nov 1 foreach ($tests as $test) { echo rangify($test) . "\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.10.0050.00418.79
8.5.00.0140.01020.46
8.4.150.0020.00014.05
8.4.140.0110.01217.84
8.4.130.0080.00218.87
8.4.120.0110.00824.11
8.4.110.0090.01119.21
8.4.100.0120.00719.24
8.4.90.0060.00420.42
8.4.80.0100.00720.46
8.4.70.0070.01018.32
8.4.60.0120.00818.96
8.4.50.0100.00918.66
8.4.40.0060.00318.02
8.4.30.0100.01019.11
8.4.20.0070.01321.71
8.4.10.0060.00319.93
8.3.280.0150.00618.68
8.3.270.0140.00616.83
8.3.260.0100.01016.86
8.3.250.0070.00218.99
8.3.240.0110.01117.32
8.3.230.0130.00617.16
8.3.220.0120.00618.95
8.3.210.0020.00517.09
8.3.200.0040.00616.66
8.3.190.0090.00717.32
8.3.180.0070.01119.04
8.3.170.0150.00319.02
8.3.160.0030.01417.55
8.3.150.0070.01117.47
8.3.140.0080.00016.89
8.3.130.0070.01418.43
8.3.120.0090.00019.02
8.3.110.0060.00316.91
8.3.100.0000.00917.06
8.3.90.0040.00416.89
8.3.80.0070.00318.81
8.3.70.0460.00717.97
8.3.60.0430.01317.97
8.3.50.0100.00617.97
8.3.40.0370.00317.97
8.3.30.0400.00717.97
8.3.20.0250.01317.97
8.3.10.0280.00317.97
8.3.00.0170.00617.97
8.2.290.0090.01020.34
8.2.280.0100.01118.59
8.2.270.0070.01117.40
8.2.260.0080.01218.44
8.2.250.0080.00017.38
8.2.240.0070.01316.87
8.2.230.0040.00420.94
8.2.220.0050.00324.06
8.2.210.0110.00426.77
8.2.200.0100.00016.63
8.2.190.0140.00817.97
8.2.180.0210.00317.97
8.2.170.0210.00518.10
8.2.160.0200.00318.00
8.2.150.0130.01017.97
8.2.140.0210.00817.97
8.2.130.0250.00417.97
8.2.120.0240.00417.97
8.2.110.0290.00317.97
8.2.100.0260.00417.97
8.2.90.0280.00817.97
8.2.80.0200.00717.97
8.2.70.0210.00517.97
8.2.60.0180.00417.97
8.2.50.0160.00518.00
8.2.40.0160.00417.97
8.2.30.0160.00417.97
8.2.20.0170.00317.97
8.2.10.0180.00317.97
8.2.00.0180.00317.97
8.1.330.0070.00422.12
8.1.320.0100.01018.50
8.1.310.0000.00818.72
8.1.300.0000.00918.77
8.1.290.0030.00630.84
8.1.280.0280.00017.97
8.1.270.0350.00017.97
8.1.260.0390.00017.97
8.1.250.0320.00317.97
8.1.240.0290.01317.97
8.1.230.0320.00317.97
8.1.220.0250.00717.97
8.1.210.0250.00017.97
8.1.200.0200.00317.97
8.1.190.0100.01017.97
8.1.180.0190.00317.97
8.1.170.0190.00517.97
8.1.160.0190.00517.97
8.1.150.0240.00017.97
8.1.140.0190.00517.97
8.1.130.0150.00517.97
8.1.120.0190.00517.97
8.1.110.0280.00417.97
8.1.100.0300.00617.97
8.1.90.0290.01317.97
8.1.80.0200.00017.97
8.1.70.0140.01017.97
8.1.60.0250.00017.97
8.1.50.0150.00717.97
8.1.40.0160.00617.97
8.1.30.0180.00517.97
8.1.20.0210.00017.97
8.1.10.0260.00017.97
8.1.00.0170.00617.97

preferences:
36.61 ms | 403 KiB | 5 Q