Skip to content

Instantly share code, notes, and snippets.

@stefpe
Created April 17, 2019 09:58
Show Gist options
  • Save stefpe/9283c289c6439db39ff499d0a3418e95 to your computer and use it in GitHub Desktop.
Save stefpe/9283c289c6439db39ff499d0a3418e95 to your computer and use it in GitHub Desktop.
Alternatives by computing the levenshtein distance in symfony
<?php
$lev = levenshtein($subname, $parts[$i]);
if ($lev <= \strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
} elseif ($exists) {
$alternatives[$collectionName] += $threshold;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment