3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hyphenate(array $numbers) { $result = []; $ref = null; foreach ($numbers as $i => $number) { if ($ref && $number == $numbers[$i - 1] + 1) { $ref = strtok($ref, "-") . "-$number"; } else { unset($ref); $ref = $number; $result[] =& $ref; } } return implode(',', $result); } var_export([ hyphenate(explode(' ', '')), hyphenate(explode(' ', '1')), hyphenate(explode(' ', '1 2')), hyphenate(explode(' ', '1 3')), hyphenate(explode(' ', '1 3 4 6')), hyphenate(explode(' ', '1 3 4 6 7')), hyphenate(explode(' ', '1 2 3 4 5')), hyphenate(explode(' ', '1 2 3 5 6 10 12 13')), ]);

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.30.0100.00721.24
8.5.20.0110.00720.06
8.5.10.0140.00516.64
8.5.00.0120.00920.21
8.4.180.0150.00819.64
8.4.170.0110.00920.63
8.4.160.0150.00923.87
8.4.150.0070.00516.81
8.4.140.0110.01117.91
8.4.130.0140.00518.67
8.4.120.0120.00723.95
8.4.110.0120.00817.80
8.4.100.0150.00518.76
8.4.90.0130.00720.31
8.4.80.0120.00518.86
8.4.70.0090.00617.78
8.4.60.0130.00818.91
8.4.50.0090.01517.93
8.4.40.0030.00617.54
8.4.30.0140.00718.78
8.4.20.0130.00619.43
8.4.10.0040.00419.57
8.3.300.0130.00820.84
8.3.290.0130.00820.75
8.3.280.0100.01018.37
8.3.270.0090.01016.65
8.3.260.0110.00916.46
8.3.250.0130.00618.95
8.3.240.0060.00216.88
8.3.230.0130.00716.49
8.3.220.0130.00518.94
8.3.210.0060.00216.59
8.3.200.0050.00416.63
8.3.190.0040.00517.28
8.3.180.0080.01120.87
8.3.170.0030.00616.85
8.3.160.0060.00316.73
8.3.150.0120.00617.05
8.3.140.0080.00017.21
8.3.130.0030.00718.59
8.3.120.0030.00620.54
8.3.110.0100.00020.94
8.3.100.0040.00424.06
8.3.90.0070.00026.77
8.3.80.0160.01326.77
8.3.70.0140.00526.77
8.3.60.0210.00026.77
8.3.50.0120.00926.77
8.3.40.0190.00026.77
8.3.30.0060.01226.77
8.3.20.0090.00926.77
8.3.10.0170.00026.77
8.3.00.0160.00026.77
8.2.300.0130.00822.28
8.2.290.0100.00620.67
8.2.280.0050.00318.42
8.2.270.0070.01017.47
8.2.260.0090.00918.31
8.2.250.0000.00916.75
8.2.240.0090.00617.18
8.2.230.0050.00322.58
8.2.220.0060.00337.54
8.2.210.0190.00026.77
8.2.200.0130.00526.77
8.2.190.0140.00326.77
8.2.180.0130.00526.77
8.2.170.0140.00526.77
8.2.160.0150.00626.77
8.2.150.0190.00026.77
8.2.140.0140.00526.77
8.2.130.0160.00426.77
8.2.120.0120.00926.77
8.2.110.0160.00326.77
8.2.100.0160.00326.77
8.2.90.0150.00326.77
8.2.80.0140.00526.77
8.2.70.0120.00826.77
8.2.60.0150.00426.77
8.2.50.0150.00426.77
8.2.40.0130.00526.77
8.2.30.0130.00326.77
8.2.20.0180.00426.77
8.2.10.0220.00026.77
8.2.00.0120.00426.77
8.1.340.0090.01020.03
8.1.330.0110.00822.07
8.1.320.0120.00815.89
8.1.310.0090.00918.71
8.1.300.0120.00618.18
8.1.290.0130.00426.77
8.1.280.0140.00526.77
8.1.270.0200.00326.77
8.1.260.0190.00026.77
8.1.250.0130.00626.77
8.1.240.0160.00026.77
8.1.230.0130.00326.77
8.1.220.0100.00726.77
8.1.210.0180.00026.77
8.1.200.0130.00426.77
8.1.190.0120.00526.77
8.1.180.0140.00326.77
8.1.170.0210.00626.77
8.1.160.0090.00926.77
8.1.150.0210.00026.77
8.1.140.0110.00526.77
8.1.130.0050.01126.77
8.1.120.0100.00726.77
8.1.110.0110.00626.77
8.1.100.0150.00226.77
8.1.90.0130.00326.77
8.1.80.0110.00526.77
8.1.70.0080.00826.77
8.1.60.0180.00026.77
8.1.50.0180.00026.77
8.1.40.0200.00026.77
8.1.30.0130.00426.77
8.1.20.0110.00826.77
8.1.10.0180.00026.77
8.1.00.0180.00026.77

preferences:
49.5 ms | 1006 KiB | 5 Q