<?php
$testStrings = [
"H3||0",
"Hallo",
"aloha",
"h",
"hallo",
"hallå",
"hel",
"helicopter",
"hellacious",
"hello",
"hello y'all",
"hello yall",
"helów",
"hey hello",
"hola",
"hêllo",
"mellow yellow",
"try",
];
$needle = 'hello';
usort($testStrings, function($a, $b) use ($needle) {
return levenshtein($needle, $a) <=> levenshtein($needle, $b);
});
var_export($testStrings);
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- array (
0 => 'hello',
1 => 'hallo',
2 => 'Hallo',
3 => 'hel',
4 => 'hêllo',
5 => 'hallå',
6 => 'helów',
7 => 'hola',
8 => 'h',
9 => 'hey hello',
10 => 'H3||0',
11 => 'aloha',
12 => 'hellacious',
13 => 'hello yall',
14 => 'try',
15 => 'helicopter',
16 => 'hello y\'all',
17 => 'mellow yellow',
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
array (
0 => 'hello',
1 => 'hallo',
2 => 'Hallo',
3 => 'hel',
4 => 'hêllo',
5 => 'hallå',
6 => 'helów',
7 => 'hola',
8 => 'h',
9 => 'hey hello',
10 => 'H3||0',
11 => 'aloha',
12 => 'hellacious',
13 => 'hello yall',
14 => 'try',
15 => 'helicopter',
16 => 'hello y\'all',
17 => 'mellow yellow',
)
- Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
- array (
0 => 'hello',
1 => 'hallo',
2 => 'hêllo',
3 => 'hel',
4 => 'Hallo',
5 => 'helów',
6 => 'hallå',
7 => 'hola',
8 => 'h',
9 => 'hey hello',
10 => 'H3||0',
11 => 'hello yall',
12 => 'hellacious',
13 => 'aloha',
14 => 'try',
15 => 'hello y\'all',
16 => 'helicopter',
17 => 'mellow yellow',
)
preferences:
157.61 ms | 402 KiB | 184 Q