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); if($count!=0){ $phoneNumber.='-'; } $phoneNumber.= $inputString[$count].$inputString[$count+1]; }else if($rem == 1){ if($count!=0){ $phoneNumber.='-'; } $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)
7.0.00.0030.04720.33
5.6.160.0130.07020.46
5.6.150.0100.07018.29
5.6.140.0000.07018.16
5.6.130.0170.04318.30
5.6.120.0030.04021.00
5.6.110.0100.06020.97
5.6.100.0200.07021.05
5.6.90.0100.08020.98
5.6.80.0130.07320.39
5.5.300.0030.05318.09
5.5.290.0130.04717.94
5.5.280.0130.07320.81
5.5.270.0070.08020.85
5.5.260.0100.04720.67
5.5.250.0030.07320.70
5.5.240.0170.07720.27

preferences:
147.08 ms | 1394 KiB | 7 Q