This function takes two main arguments that are $search
and $possibleMatches
and
looks for a the closest word to $search
in the $possibleMatches
list.
$search = 'fio';
$possibleMatches = ['foo', 'bar', 'baz'];
if (!in_array($search, $possibleMatches)) {
throw didYouMean($search, array_keys($possibleMatches));
}
// Output: Unable to find a value matching with "fio". Did you mean "foo"?