<?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, fn($a, $b) =>
levenshtein($needle, $a) <=> levenshtein($needle, $b)
?: similar_text($needle, $b) <=> similar_text($needle, $a)
);
var_export($testStrings);
preferences:
55.45 ms | 402 KiB | 5 Q