public static function suggestionList($input, array $options)
    {
        $optionsByDistance = [];
        $inputThreshold    = mb_strlen($input) / 2;
        foreach ($options as $option) {
            if ($input === $option) {
                $distance = 0;
            } else {
                $distance = (strtolower($input) === strtolower($option)
                    ? 1
                    : levenshtein($input, $option));
            }
            $threshold = max($inputThreshold, mb_strlen($option) / 2, 1);
            if ($distance > $threshold) {
                continue;
            }

            $optionsByDistance[$option] = $distance;
        }

        asort($optionsByDistance);

        return array_keys($optionsByDistance);
    }
public static function suggestionList($input, array $options)
    {
        $optionsByDistance = [];
        $inputThreshold    = mb_strlen($input) / 2;
        foreach ($options as $option) {
            if ($input === $option) {
                $distance = 0;
            } else {
                $distance = (strtolower($input) === strtolower($option)
                    ? 1
                    : levenshtein($input, $option));
            }
            $threshold = max($inputThreshold, mb_strlen($option) / 2, 1);
            if ($distance > $threshold) {
                continue;
            }

            $optionsByDistance[$option] = $distance;
        }

        asort($optionsByDistance);

        return array_keys($optionsByDistance);
    }
public static function suggestionList ( $ input , array $ options ) { $ optionsByDistance = [ ] ; $ inputThreshold = mb_strlen ( $ input ) / 2 ; foreach ( $ options as $ option ) { if ( $ input === $ option ) { $ distance = 0 ; } else { $ distance = ( strtolower ( $ input ) === strtolower ( $ option ) ? 1 : levenshtein ( $ input , $ option ) ) ; } $ threshold = max ( $ inputThreshold , mb_strlen ( $ option ) / 2 , 1 ) ; if ( $ distance > $ threshold ) { continue ; } $ optionsByDistance [ $ option ] = $ distance ; } asort ( $ optionsByDistance ) ; return array_keys ( $ optionsByDistance ) ; }
Given an invalid input string and a list of valid options, returns a filtered
list of valid options sorted based on their similarity with the input.

Includes a custom alteration from Damerau-Levenshtein to treat case changes
as a single edit which helps identify mis-cased values with an edit distance
of 1

@param string   $input
@param string[] $options

@return string[]
Given an invalid input string and a list of valid options returns a filtered list of valid options sorted based on their similarity with the input .