<?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);
preferences:
27.61 ms | 402 KiB | 5 Q