3v4l.org

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

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.00416.88
8.3.50.0120.00921.22
8.3.40.0070.00719.09
8.3.30.0040.01119.00
8.3.20.0040.00420.15
8.3.10.0040.00423.65
8.3.00.0060.00323.63
8.2.180.0070.00718.54
8.2.170.0120.00622.96
8.2.160.0100.00320.27
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00420.91
8.2.120.0040.00426.35
8.2.110.0150.00621.10
8.2.100.0070.00318.18
8.2.90.0040.00419.17
8.2.80.0030.00618.00
8.2.70.0040.00417.88
8.2.60.0040.00417.90
8.2.50.0050.00318.07
8.2.40.0080.00022.23
8.2.30.0060.00320.73
8.2.20.0040.00417.97
8.2.10.0070.00318.32
8.2.00.0040.00418.20
8.1.280.0040.01425.92
8.1.270.0080.00023.91
8.1.260.0070.00028.09
8.1.250.0080.00028.09
8.1.240.0030.00719.38
8.1.230.0080.00317.95
8.1.220.0000.00817.74
8.1.210.0090.00018.77
8.1.200.0030.00717.48
8.1.190.0030.00517.35
8.1.180.0000.00818.10
8.1.170.0080.00018.66
8.1.160.0040.00420.80
8.1.150.0070.00019.03
8.1.140.0070.00017.67
8.1.130.0000.00817.72
8.1.120.0030.00517.59
8.1.110.0000.00717.64
8.1.100.0000.00717.61
8.1.90.0000.00717.54
8.1.80.0000.00917.50
8.1.70.0000.00817.66
8.1.60.0040.00417.63
8.1.50.0030.00617.58
8.1.40.0000.00917.58
8.1.30.0030.00517.80
8.1.20.0040.00417.81
8.1.10.0030.00617.62
8.1.00.0040.00417.66
8.0.300.0000.00718.77
8.0.290.0000.00716.88
8.0.280.0000.00818.48
8.0.270.0030.00517.04
8.0.260.0030.00317.30
8.0.250.0000.00617.18
8.0.240.0030.00317.18
8.0.230.0000.00717.14
8.0.220.0040.00417.20
8.0.210.0000.00717.01
8.0.200.0030.00317.07
8.0.190.0000.00817.24
8.0.180.0080.00017.10
8.0.170.0030.00517.12
8.0.160.0000.00817.09
8.0.150.0030.00617.10
8.0.140.0070.00017.05
8.0.130.0000.00713.59
8.0.120.0050.00317.18
8.0.110.0030.00517.11
8.0.100.0000.00716.97
8.0.90.0080.00017.22
8.0.80.0110.00617.14
8.0.70.0030.00517.08
8.0.60.0000.00817.18
8.0.50.0070.00017.21
8.0.30.0080.00817.40
8.0.20.0100.01217.41
8.0.10.0060.00317.28
8.0.00.0120.00816.94
7.4.330.0000.00616.69
7.4.320.0030.00316.77
7.4.300.0060.00016.89
7.4.290.0000.00716.80
7.4.280.0050.00316.93
7.4.270.0000.00716.89
7.4.260.0030.00316.73
7.4.250.0030.00316.86
7.4.240.0050.00216.77
7.4.230.0030.00316.64
7.4.220.0110.00816.99
7.4.210.0090.00916.86
7.4.200.0000.00716.91
7.4.160.0040.01216.68
7.4.150.0130.00417.40
7.4.140.0060.01117.86
7.4.130.0110.00616.89
7.4.120.0030.01416.84
7.4.110.0030.01916.93
7.4.100.0030.01316.80
7.4.90.0030.01416.70
7.4.80.0090.01319.39
7.4.70.0040.01516.69
7.4.60.0110.00616.78
7.4.50.0100.00716.86
7.4.40.0120.00916.73
7.4.30.0080.00816.71
7.4.00.0080.01015.24
7.3.330.0000.00513.30
7.3.320.0000.00513.35
7.3.310.0040.00416.57
7.3.300.0070.00016.46
7.3.290.0000.00716.54
7.3.280.0090.00916.54
7.3.270.0000.01717.40
7.3.260.0120.00616.70
7.3.250.0110.00716.67
7.3.240.0110.00816.62
7.3.230.0140.01116.72
7.3.210.0070.01116.71
7.3.200.0080.01916.80
7.3.190.0030.01416.67
7.3.180.0070.01316.54
7.3.170.0000.01716.75
7.3.160.0070.01016.89
7.3.120.0090.00914.80
7.3.110.0110.00715.18
7.3.100.0030.01015.12
7.3.90.0130.00615.10
7.3.80.0040.01415.10
7.3.70.0120.00015.02
7.3.60.0000.01515.13
7.3.50.0000.01514.96
7.3.40.0060.00914.91
7.3.30.0000.01514.84
7.3.20.0030.01316.82
7.3.10.0000.01616.93
7.3.00.0060.00617.00
7.2.330.0140.00316.81
7.2.320.0100.00616.78
7.2.310.0070.01116.81
7.2.300.0070.01116.91
7.2.290.0000.01716.95
7.2.250.0110.00715.23
7.2.240.0030.01315.46
7.2.230.0070.00715.00
7.2.220.0100.00715.19
7.2.210.0030.01415.08
7.2.200.0120.00315.00
7.2.190.0060.00615.00
7.2.180.0040.00715.34
7.2.170.0000.01415.27
7.2.00.0040.01219.54
7.1.330.0060.00916.04
7.1.320.0070.00715.89
7.1.310.0040.01216.01
7.1.300.0060.00315.99
7.1.290.0080.00616.07
7.1.280.0110.00416.12
7.1.270.0080.00416.12
7.1.260.0060.00315.73
7.1.100.0030.00918.38
7.1.70.0000.00817.32
7.1.60.0070.01819.06
7.1.50.0170.00817.20
7.1.00.0030.07322.45
7.0.200.1300.00714.82
7.0.60.0170.07319.96
7.0.50.0030.05317.87
7.0.40.0030.07020.06
7.0.30.0300.08020.22
7.0.20.0330.07720.18
7.0.10.0130.07320.22
7.0.00.0000.06020.21
5.6.280.0070.05721.12
5.6.210.0100.05720.57
5.6.200.0030.08718.18
5.6.190.0130.08320.41
5.6.180.0070.04320.64
5.6.170.0400.07020.40
5.6.160.0130.08720.49
5.6.150.0000.05718.18
5.6.140.0070.04318.16
5.6.130.0100.06718.21
5.6.120.0000.04721.02
5.6.110.0130.08321.03
5.6.100.0030.08021.01
5.6.90.0030.07721.01
5.6.80.0130.07320.41
5.5.350.4370.03320.39
5.5.340.0030.08318.02
5.5.330.0100.05320.58
5.5.320.0270.04720.32
5.5.310.0270.07720.27
5.5.300.0100.04717.87
5.5.290.0070.07717.98
5.5.280.0100.05320.88
5.5.270.0100.07720.87
5.5.260.0030.06720.88
5.5.250.0070.07020.70
5.5.240.0130.07320.19

preferences:
48.85 ms | 401 KiB | 5 Q