3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* PARAMETERS: * $length(int) = length of final code (excluding separators) * $type(string) = type of code (numbers|letters|mixed)("mixed" by default) * $size(string) = size of code (uppercase|lowercase|mixed)("uppercase" by default) * $sep(array) = * [0](bool) : if use separator ("false" by default) * [1](int) : frequency of separation ("5" by defaul$next != null && t) * [2](string) : separator ("-" by default) * RETURNS: * $code(string) = random-generated code */ function generateCode($length, $type = "mixed", $size = "uppercase", $sep = array(false, 5, "-")){ $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $nums = "0123456789"; if($type == "numbers") $arr = $nums; else if($type == "letters") $arr = $chars; else if($type == "mixed") $arr = $nums.$chars; echo $arr."<br>"; // HERE I GET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" if($size == "mixed") $arr .= strtolower($chars); // HERE IS THE PROBLEM else if($size == "lowercase"); $arr = strtolower($arr); echo $arr."<br>"; // HERE I GET "0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" // BUT I SHOULD GET "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" $arr = str_split($arr); if($sep[0] == true){ $length += ceil($length / $sep[1] - 1); $next = $sep[1]; } for($i = 0; $i < $length; $i++){ if($next != null && $next == $i){ $next += $sep[1] + 1; $code .= $sep[2]; } else $code .= $arr[rand(0, sizeof($arr) - 1)]; } return $code; } echo generateCode(5, "mixed", "mixed");

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.2.00.0080.00819.62
7.1.70.0100.00017.27
7.1.60.0110.01419.46
7.1.50.0040.01216.92
7.1.00.0030.09022.37
7.0.200.0170.00714.62
7.0.140.0000.07322.06
7.0.60.0030.07320.02
7.0.50.0030.05017.89
7.0.40.0100.09720.40
7.0.30.0470.05320.24
7.0.20.0230.04720.30
7.0.10.0100.05020.20
7.0.00.0030.04020.11
5.6.280.0070.07321.00
5.6.210.0100.07720.55
5.6.200.0030.07318.22
5.6.190.0100.03720.43
5.6.180.0230.07320.48
5.6.170.0300.04720.45
5.6.160.0100.05720.48
5.6.150.0100.05018.19
5.6.140.0070.03718.21
5.6.130.0030.04018.20
5.6.120.0170.07320.98
5.6.110.0070.04721.02
5.6.100.0100.07321.02
5.6.90.0070.03721.04
5.6.80.0100.07320.38
5.6.70.4030.04020.54
5.5.350.0070.07320.42
5.5.340.0070.08317.96
5.5.330.0100.08320.42
5.5.320.0070.08320.37
5.5.310.0170.04020.27
5.5.300.0070.04718.01
5.5.290.0030.07717.95
5.5.280.0030.08720.81
5.5.270.0070.08320.81
5.5.260.0100.08020.74
5.5.250.0130.06320.57
5.5.240.0170.04020.27
5.4.450.0130.05319.61
5.4.440.0800.06019.34
5.4.430.0730.06719.20
5.4.420.0670.00019.39
5.4.410.0030.07019.03
5.4.400.0200.05018.77
5.4.390.0330.04018.73
5.4.380.0270.07718.59
5.4.370.0030.04318.57
5.4.360.0100.04018.74
5.4.350.0060.03512.03
5.4.340.0070.03812.03
5.4.320.0120.03912.52
5.4.310.0090.03612.52
5.4.300.0070.03712.52
5.4.290.0040.04112.50
5.4.280.0080.03312.39
5.4.270.0060.03612.39
5.4.260.0040.04012.39
5.4.250.0050.03912.40
5.4.240.0080.03712.40
5.4.230.0080.03712.38
5.4.220.0030.04112.38
5.4.210.0050.04112.39
5.4.200.0070.04012.39
5.4.190.0050.03812.38
5.4.180.0090.03512.38
5.4.170.0090.04912.39
5.4.160.0080.04612.39
5.4.150.0060.03812.38
5.4.140.0070.03912.07
5.4.130.0090.03412.05
5.4.120.0090.04012.02
5.4.110.0050.03612.01
5.4.100.0110.03112.01
5.4.90.0040.03912.01
5.4.80.0060.03812.01
5.4.70.0050.03512.00
5.4.60.0080.03312.00
5.4.50.0050.03612.01
5.4.40.0060.03511.99
5.4.30.0080.03411.99
5.4.20.0060.03511.99
5.4.10.0050.03511.99
5.4.00.0080.03411.48
5.3.290.0060.03912.80
5.3.280.0020.04512.71
5.3.270.0090.05012.72
5.3.260.0060.03912.72
5.3.250.0050.03712.71
5.3.240.0060.04512.72
5.3.230.0050.04212.71
5.3.220.0050.03812.68
5.3.210.0060.05512.68
5.3.200.0070.03712.68
5.3.190.0070.03812.67
5.3.180.0070.03612.68
5.3.170.0050.03712.67
5.3.160.0040.03712.67
5.3.150.0060.03712.68
5.3.140.0060.03812.66
5.3.130.0050.04012.66
5.3.120.0070.03912.66
5.3.110.0090.03612.66
5.3.100.0040.03812.14
5.3.90.0030.03812.12
5.3.80.0050.03612.11
5.3.70.0040.03812.11
5.3.60.0080.05012.09
5.3.50.0040.04312.04
5.3.40.0120.04512.04
5.3.30.0130.04912.00
5.3.20.0080.03811.79
5.3.10.0060.04511.75
5.3.00.0100.04511.73
5.2.170.0080.0389.24
5.2.160.0090.0299.24
5.2.150.0070.0319.24
5.2.140.0060.0339.23
5.2.130.0050.0439.20
5.2.120.0040.0439.20
5.2.110.0060.0389.20
5.2.100.0080.0399.20
5.2.90.0060.0429.20
5.2.80.0070.0379.20
5.2.70.0040.0349.19
5.2.60.0070.0299.14
5.2.50.0060.0309.12
5.2.40.0070.0309.09
5.2.30.0170.0569.06
5.2.20.0210.0379.05
5.2.10.0240.0528.96
5.2.00.0050.0428.82
5.1.60.0100.0288.11
5.1.50.0090.0398.10
5.1.40.0060.0358.09
5.1.30.0070.0368.43
5.1.20.0100.0408.46
5.1.10.0070.0388.18
5.1.00.0170.0498.18
5.0.50.0080.0296.66
5.0.40.0070.0306.52
5.0.30.0070.0436.34
5.0.20.0130.0346.30
5.0.10.0060.0286.28
5.0.00.0050.0416.28
4.4.90.0040.0234.78
4.4.80.0040.0224.75
4.4.70.0040.0154.76
4.4.60.0050.0204.75
4.4.50.0080.0124.77
4.4.40.0040.0244.71
4.4.30.0020.0174.76
4.4.20.0030.0164.85
4.4.10.0060.0204.85
4.4.00.0030.0304.76
4.3.110.0060.0204.66
4.3.100.0070.0184.66
4.3.90.0030.0184.63
4.3.80.0040.0304.58
4.3.70.0040.0194.63
4.3.60.0040.0134.63
4.3.50.0030.0164.63
4.3.40.0030.0254.54
4.3.30.0000.0183.33
4.3.20.0010.0183.31
4.3.10.0050.0193.27
4.3.00.0330.0176.81

preferences:
34.01 ms | 401 KiB | 5 Q