src/StringUtils.php
public static function mostSimilar($needle, $wordPool)
    {
        $distancePool = [];

        $needle = mb_strtolower($needle);

        foreach ($wordPool as $word) {
            $distance = similar_text($needle, mb_strtolower($word));

            if (!isset($distancePool[$distance])) {
                $distancePool[$distance] = [];
            }

            $distancePool[$distance][] = $word;
        }

        $min = max(array_keys($distancePool));

        // if distance is the same, we just pick the first we can get
        return $distancePool[$min][0];
    }
public static function mostSimilar($needle, $wordPool)
    {
        $distancePool = [];

        $needle = mb_strtolower($needle);

        foreach ($wordPool as $word) {
            $distance = similar_text($needle, mb_strtolower($word));

            if (!isset($distancePool[$distance])) {
                $distancePool[$distance] = [];
            }

            $distancePool[$distance][] = $word;
        }

        $min = max(array_keys($distancePool));

        // if distance is the same, we just pick the first we can get
        return $distancePool[$min][0];
    }
public static function mostSimilar ( $ needle , $ wordPool ) { $ distancePool = [ ] ; $ needle = mb_strtolower ( $ needle ) ; foreach ( $ wordPool as $ word ) { $ distance = similar_text ( $ needle , mb_strtolower ( $ word ) ) ; if ( ! isset ( $ distancePool [ $ distance ] ) ) { $ distancePool [ $ distance ] = [ ] ; } $ distancePool [ $ distance ] [ ] = $ word ; } $ min = max ( array_keys ( $ distancePool ) ) ; // if distance is the same, we just pick the first we can get return $ distancePool [ $ min ] [ 0 ] ; }
Finds a string in a pool of strings which is most similar to the given
needle.

@param string $needle
@param array  $wordPool
Finds a string in a pool of strings which is most similar to the given needle .