3v4l.org

run code in 300+ PHP versions simultaneously
<?php $inputString = "80"; $pattern = '/[ \-]/'; $replacement = ''; $inputString = preg_replace($pattern,$replacement,$inputString); $inputString = trim($inputString); $count = strlen($inputString); //echo $inputString;exit; $rem = ($count%3); if ($rem == 1){ $pos =4; $count = ($count - $pos); } else if($rem == 2) { $pos = 2; $count = ($count - $pos); } $phoneNumber = ""; for($k=0;$k<$count;$k++){ if($k % 3 !=0 || $k == 0){ $phoneNumber = $phoneNumber.$inputString[$k]; $phoneNumber = trim($phoneNumber); }else{ $phoneNumber = $phoneNumber.'-'.$inputString[$k]; } } //echo $phoneNumber;exit; if($rem == 2){ $phoneNumber.= '-'.$inputString[$count].$inputString[$count+1]; }else if($rem == 1){ $phoneNumber.= '-'.$inputString[$count].$inputString[$count+1].'-'.$inputString[$count+2].$inputString[$count+3]; } echo $phoneNumber;exit;

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.3.60.0110.01116.88
8.3.50.0160.00321.23
8.3.40.0060.01019.17
8.3.30.0070.00718.84
8.3.20.0040.00420.34
8.3.10.0040.00423.66
8.3.00.0050.00523.66
8.2.180.0090.00918.54
8.2.170.0080.00822.96
8.2.160.0120.00322.25
8.2.150.0090.00024.18
8.2.140.0040.00424.66
8.2.130.0000.00821.12
8.2.120.0050.00326.35
8.2.110.0030.00620.98
8.2.100.0060.00618.16
8.2.90.0040.00419.29
8.2.80.0000.00817.97
8.2.70.0030.00617.88
8.2.60.0030.00517.93
8.2.50.0050.00318.07
8.2.40.0040.00422.28
8.2.30.0040.00420.68
8.2.20.0030.00518.00
8.2.10.0050.00418.13
8.2.00.0030.00518.16
8.1.280.0140.00725.92
8.1.270.0060.00323.82
8.1.260.0080.00028.09
8.1.250.0080.00028.09
8.1.240.0060.01622.05
8.1.230.0030.00919.18
8.1.220.0050.00317.74
8.1.210.0000.00818.77
8.1.200.0030.00617.48
8.1.190.0030.00617.50
8.1.180.0040.00418.10
8.1.170.0090.00018.77
8.1.160.0040.00420.79
8.1.150.0070.00019.00
8.1.140.0000.00819.75
8.1.130.0000.00717.82
8.1.120.0100.00017.56
8.1.110.0000.00717.64
8.1.100.0070.00017.63
8.1.90.0000.00817.51
8.1.80.0000.00917.52
8.1.70.0000.00817.67
8.1.60.0080.00017.72
8.1.50.0040.00417.57
8.1.40.0000.00717.59
8.1.30.0080.00017.83
8.1.20.0060.00317.67
8.1.10.0050.00317.67
8.1.00.0040.00417.68
8.0.300.0050.00318.77
8.0.290.0040.00417.00
8.0.280.0000.00718.48
8.0.270.0030.00317.28
8.0.260.0000.00717.29
8.0.250.0030.00317.20
8.0.240.0040.00417.05
8.0.230.0040.00417.18
8.0.220.0030.00317.18
8.0.210.0030.00316.99
8.0.200.0030.00317.14
8.0.190.0040.00417.07
8.0.180.0050.00317.20
8.0.170.0040.00417.13
8.0.160.0000.00917.11
8.0.150.0030.00617.09
8.0.140.0000.00717.00
8.0.130.0030.00313.57
8.0.120.0030.00517.17
8.0.110.0040.00417.09
8.0.100.0000.00717.05
8.0.90.0000.00717.14
8.0.80.0090.00617.17
8.0.70.0070.00017.25
8.0.60.0040.00417.05
8.0.50.0040.00417.22
8.0.30.0110.00717.30
8.0.20.0140.01717.45
8.0.10.0000.00717.25
8.0.00.0120.00616.98
7.4.330.0000.00516.67
7.4.320.0000.00616.81
7.4.300.0070.00016.90
7.4.290.0000.00716.80
7.4.280.0000.00916.77
7.4.270.0000.00716.88
7.4.260.0040.00416.87
7.4.250.0070.00016.76
7.4.240.0000.00716.79
7.4.230.0000.00816.64
7.4.220.0090.00916.83
7.4.210.0070.01016.85
7.4.200.0070.00017.00
7.4.160.0130.00316.75
7.4.150.0100.00717.40
7.4.140.0140.00817.86
7.4.130.0110.00616.86
7.4.120.0060.01416.77
7.4.110.0060.01216.79
7.4.100.0090.01216.86
7.4.90.0070.01016.69
7.4.80.0070.01519.39
7.4.70.0070.01116.70
7.4.60.0150.00616.71
7.4.50.0030.00916.81
7.4.40.0030.01416.88
7.4.30.0150.00316.84
7.4.00.0040.00815.07
7.3.330.0060.00013.47
7.3.320.0000.00513.30
7.3.310.0030.00616.70
7.3.300.0000.00816.56
7.3.290.0030.00316.57
7.3.280.0080.00816.54
7.3.270.0070.01117.40
7.3.260.0110.00516.68
7.3.250.0120.00716.66
7.3.240.0070.01116.57
7.3.230.0080.00816.73
7.3.210.0140.00316.53
7.3.200.0090.00916.56
7.3.190.0070.01616.52
7.3.180.0070.01016.61
7.3.170.0070.01016.68
7.3.160.0000.01816.61
7.2.330.0100.00717.00
7.2.320.0030.01316.92
7.2.310.0170.00316.93
7.2.300.0080.01116.79
7.2.290.0000.01816.87
7.2.00.0040.00819.62
7.1.100.0120.00916.43
7.1.70.0030.01017.50
7.1.60.0030.01719.06
7.1.50.0130.01317.25
7.1.00.0000.08022.30
7.0.200.0190.01114.83
7.0.60.0030.06719.83
7.0.50.0070.07317.72
7.0.40.0030.04320.08
7.0.30.0330.08720.05
7.0.20.0270.08320.10
7.0.10.0070.08020.14
7.0.00.0100.06320.13
5.6.280.0070.06720.79
5.6.210.0030.04320.53
5.6.200.0030.06018.22
5.6.190.0130.04320.77
5.6.180.0100.07720.34
5.6.170.0370.05020.50
5.6.160.0100.10020.33
5.6.150.0100.07318.09
5.6.140.0100.08018.12
5.6.130.0170.07318.11
5.6.120.0100.03721.00
5.6.110.0130.08021.03
5.6.100.0170.06721.11
5.6.90.0070.05320.93
5.6.80.0070.07320.40
5.5.350.3900.05020.47
5.5.340.0100.07717.99
5.5.330.0030.04320.13
5.5.320.0300.04720.28
5.5.310.0300.07320.30
5.5.300.0170.04018.01
5.5.290.0170.06718.02
5.5.280.0070.08720.80
5.5.270.0030.06720.89
5.5.260.0070.05020.77
5.5.250.0130.07720.58
5.5.240.0170.08020.04

preferences:
43.04 ms | 401 KiB | 5 Q