3v4l.org

run code in 300+ PHP versions simultaneously
<?php // input misspelled word $input = 'carrot'; // array of words to check against $words = array('apple','pineapple','banana','orange', 'radish','carrot','pea','bean','potato'); // no shortest distance found, yet $shortest = -1; // loop through words to find the closest foreach ($words as $word) { // calculate the distance between the input word, // and the current word $lev = levenshtein($input, $word); // check for an exact match if ($lev == 0) { // closest word is this one (exact match) $closest = $word; $shortest = 0; // break out of the loop; we've found an exact match break; } // if this distance is less than the next found shortest // distance, OR if a next shortest word has not yet been found if ($lev <= $shortest || $shortest < 0) { // set the closest match, and shortest distance $closest = $word; $shortest = $lev; } } echo "Input word: $input\n"; if ($shortest == 0) { echo "Exact match found: $closest\n"; } else { echo $lev."\n"; echo "Did you mean: $closest?\n"; }

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.0100.01018.05
8.3.50.0100.00722.11
8.3.40.0110.00718.71
8.3.30.0090.00919.13
8.3.20.0080.00020.46
8.3.10.0060.00822.10
8.3.00.0080.00022.46
8.2.180.0080.00818.17
8.2.170.0110.00722.96
8.2.160.0150.00420.94
8.2.150.0080.00024.18
8.2.140.0110.00024.66
8.2.130.0000.00826.16
8.2.120.0080.00417.50
8.2.110.0070.00322.21
8.2.100.0080.00419.64
8.2.90.0040.00419.22
8.2.80.0060.00317.97
8.2.70.0080.00017.63
8.2.60.0000.00917.92
8.2.50.0040.00418.07
8.2.40.0000.00718.16
8.2.30.0050.00218.14
8.2.20.0070.00017.73
8.2.10.0070.00017.77
8.2.00.0040.00417.75
8.1.280.0170.00325.92
8.1.270.0000.00822.21
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0080.00023.79
8.1.230.0090.00319.03
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0070.00317.35
8.1.190.0040.00417.39
8.1.180.0040.00418.61
8.1.170.0030.00618.56
8.1.160.0040.00422.04
8.1.150.0060.00318.64
8.1.140.0000.00717.47
8.1.130.0030.00317.84
8.1.120.0040.00417.39
8.1.110.0050.00317.39
8.1.100.0000.00917.54
8.1.90.0000.00717.47
8.1.80.0040.00417.38
8.1.70.0040.00417.43
8.1.60.0000.00717.62
8.1.50.0060.00317.42
8.1.40.0000.00717.50
8.1.30.0030.00517.65
8.1.20.0020.00517.73
8.1.10.0050.00317.54
8.1.00.0000.00717.43
8.0.300.0070.00018.77
8.0.290.0000.00717.04
8.0.280.0000.00718.38
8.0.270.0030.00517.31
8.0.260.0030.00316.84
8.0.250.0000.00916.96
8.0.240.0000.00716.86
8.0.230.0040.00416.88
8.0.220.0000.00716.88
8.0.210.0070.00016.91
8.0.200.0090.00316.80
8.0.190.0050.00317.02
8.0.180.0080.00016.78
8.0.170.0050.00216.96
8.0.160.0000.00716.86
8.0.150.0040.00416.86
8.0.140.0000.00716.86
8.0.130.0030.00313.32
8.0.120.0040.00416.76
8.0.110.0000.00716.75
8.0.100.0050.00217.02
8.0.90.0040.00416.86
8.0.80.0120.00416.87
8.0.70.0030.00516.72
8.0.60.0050.00317.00
8.0.50.0000.00716.80
8.0.30.0080.01117.35
8.0.20.0060.01217.40
8.0.10.0070.00016.84
8.0.00.0060.01816.86
7.4.330.0000.00515.10
7.4.320.0070.00016.53
7.4.300.0060.00016.46
7.4.290.0030.00316.59
7.4.280.0000.00716.62
7.4.270.0040.00416.51
7.4.260.0060.00616.52
7.4.250.0050.00316.62
7.4.240.0020.00616.56
7.4.230.0000.00716.55
7.4.220.0100.00716.55
7.4.210.0060.01116.62
7.4.200.0000.00716.68
7.4.190.0000.00716.68
7.4.160.0060.01016.49
7.4.150.0060.01217.40
7.4.140.0060.01117.86
7.4.130.0090.00816.45
7.4.120.0100.00916.59
7.4.110.0130.00616.44
7.4.100.0110.00816.54
7.4.90.0100.01416.49
7.4.80.0070.01019.39
7.4.70.0090.01116.34
7.4.60.0070.01116.53
7.4.50.0080.00016.39
7.4.40.0000.01922.77
7.4.30.0180.00316.45
7.4.00.0060.00614.68
7.3.330.0000.00713.26
7.3.320.0000.00513.21
7.3.310.0030.00416.48
7.3.300.0060.00016.34
7.3.290.0030.01216.34
7.3.280.0090.00916.33
7.3.270.0070.01017.40
7.3.260.0210.00316.54
7.3.250.0140.00616.48
7.3.240.0130.01016.43
7.3.230.0130.00316.39
7.3.210.0070.01016.28
7.3.200.0060.01319.39
7.3.190.0120.00616.38
7.3.180.0100.01016.63
7.3.170.0060.01016.71
7.3.160.0040.01116.64
7.3.120.0040.01115.16
7.2.330.0100.00716.67
7.2.320.0070.01116.71
7.2.310.0060.01716.75
7.2.300.0230.00016.46
7.2.290.0100.00716.77
7.2.00.0080.00519.43
7.1.100.0060.00617.91
7.1.70.0000.00817.29
7.1.60.0090.01519.82
7.1.50.0280.00034.52
7.1.00.0070.06722.47
7.0.200.0150.00516.63
7.0.140.0070.07321.95
7.0.60.0070.07719.95
7.0.50.0070.05317.84
7.0.40.0130.05020.20
7.0.30.0270.05020.18
7.0.20.0270.05320.18
7.0.10.0270.07320.16
7.0.00.0130.07320.30
5.6.280.0030.07320.84
5.6.210.0000.06320.71
5.6.200.0100.03318.19
5.6.190.0030.04720.57
5.6.180.3530.04320.27
5.6.170.0230.05020.33
5.6.160.0000.04720.48
5.6.150.0100.07718.18
5.6.140.0070.05718.21
5.6.130.0030.08018.20
5.6.120.0070.04020.99
5.6.110.0100.08021.11
5.6.100.0030.04720.97
5.6.90.0100.08321.12
5.6.80.0070.06320.50
5.6.70.0270.07320.34
5.5.350.0030.08720.35
5.5.340.0100.08018.03
5.5.330.0030.08720.37
5.5.320.0230.05320.27
5.5.310.0300.06720.45
5.5.300.0100.04318.03
5.5.290.0070.04717.86
5.5.280.0100.03720.90
5.5.270.0130.08020.98
5.5.260.0100.06720.64
5.5.250.0070.03720.46
5.5.240.0070.08020.26
5.4.450.0600.07719.48
5.4.440.0700.05719.24
5.4.430.0470.06319.63
5.4.420.0230.04019.25
5.4.410.0800.05019.11
5.4.400.1770.00018.81
5.4.390.1530.00018.71
5.4.380.0230.06318.63
5.4.370.0200.05318.78
5.4.360.0430.03718.68
5.4.350.0370.05018.66
5.4.340.0330.05018.50
5.4.320.0060.03812.45
5.4.310.0070.05312.45
5.4.300.0040.03812.45
5.4.290.0080.03612.46
5.4.280.0080.05012.35
5.4.270.0050.03812.35
5.4.260.0100.04718.70
5.4.250.0070.05318.92
5.4.240.0100.04718.82
5.4.230.0070.05318.77
5.4.220.0070.06019.01
5.4.210.0100.05018.88
5.4.200.0070.05018.73
5.4.190.0070.05318.86
5.4.180.0130.04718.75
5.4.170.0200.05318.86
5.4.160.0070.05018.68
5.4.150.0030.06018.85
5.4.140.0070.05716.42
5.4.130.0030.07016.23
5.4.120.0100.04716.45
5.4.110.0030.05316.20
5.4.100.0100.06716.51
5.4.90.0070.07016.41
5.4.80.0030.05716.27
5.4.70.0130.06316.38
5.4.60.0170.04716.45
5.4.50.0100.06316.45
5.4.40.0170.06016.36
5.4.30.0130.05316.32
5.4.20.0070.05016.30
5.4.10.0170.06316.24
5.4.00.0030.07315.71
5.3.290.0080.04312.80
5.3.280.0100.05314.55
5.3.270.0100.07314.62
5.3.260.0070.06714.38
5.3.250.0130.05714.38
5.3.240.0070.07714.65
5.3.230.0030.05314.48
5.3.220.0100.04714.48
5.3.210.0170.04714.52
5.3.200.0130.06714.57
5.3.190.0070.07714.66
5.3.180.0170.06014.34
5.3.170.0030.07314.56
5.3.160.0070.05714.40
5.3.150.0170.06014.45
5.3.140.0170.06714.71
5.3.130.0100.04714.58
5.3.120.0170.07314.70
5.3.110.0070.07014.56
5.3.100.0030.05314.05
5.3.90.0130.04714.01
5.3.80.0070.05713.95
5.3.70.0170.05313.90
5.3.60.0030.05313.70
5.3.50.0030.05713.80
5.3.40.0130.05014.10
5.3.30.0070.05314.06
5.3.20.0270.04313.73
5.3.10.0130.04013.50
5.3.00.0070.06313.57
5.2.170.0130.03711.25
5.2.160.0030.04311.16
5.2.150.0070.04011.07
5.2.140.0070.03711.14
5.2.130.0100.03311.02
5.2.120.0030.05311.00
5.2.110.0070.05311.12
5.2.100.0100.04311.12
5.2.90.0100.05011.12
5.2.80.0100.04011.01
5.2.70.0000.05011.09
5.2.60.0100.05311.07
5.2.50.0170.03010.96
5.2.40.0100.03711.01
5.2.30.0170.03310.81
5.2.20.0030.04010.98
5.2.10.0030.04010.76
5.2.00.0030.04310.73
5.1.60.0030.0509.97
5.1.50.0100.03010.24
5.1.40.0070.03310.23
5.1.30.0070.04010.18
5.1.20.0130.03010.28
5.1.10.0070.0479.97
5.1.00.0100.03010.27
5.0.50.0070.0238.79
5.0.40.0030.0278.46
5.0.30.0030.0438.29
5.0.20.0070.0308.12
5.0.10.0070.0238.21
5.0.00.0070.0438.16
4.4.90.0070.0206.90
4.4.80.0030.0306.90
4.4.70.0000.0236.90
4.4.60.0000.0336.90
4.4.50.0000.0236.90
4.4.40.0100.0336.90
4.4.30.0030.0336.90
4.4.20.0030.0206.90
4.4.10.0030.0306.90
4.4.00.0000.0376.90
4.3.110.0030.0276.90
4.3.100.0100.0176.90
4.3.90.0030.0206.90
4.3.80.0000.0336.90
4.3.70.0030.0206.90
4.3.60.0070.0176.90
4.3.50.0030.0206.90
4.3.40.0070.0406.90
4.3.30.0070.0276.90
4.3.20.0000.0236.90
4.3.10.0000.0276.90
4.3.00.0030.0279.30

preferences:
39.33 ms | 401 KiB | 5 Q