v-bartusevicius / levenshtein-array-sort
Sorts haystack with strings by Levenshtein distance to needle
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
pkg:composer/v-bartusevicius/levenshtein-array-sort
Requires
- php: >=5.3.2
Requires (Dev)
This package is not auto-updated.
Last update: 2025-05-10 20:00:31 UTC
README
Sorts given array of strings by Levenshtein distance.
Simply use:
$needle = 'text'; $haystack = array('texas', 'test', 'random'); $sorter = new ArraySort(); $result = $sorter->sort($needle, $haystack); print_r($result);
The result will be represented as ordered array with keys as Levenshtein distance to needle:
Array
(
[1] => test
[2] => texas
[6] => random
)
In case there are same distances to needle, the nested array will be created:
$needle = 'text'; $haystack = array('texas', 'test', 'texts', 'random'); $result = $sorter->sort($needle, $haystack); print_r($result);
Array
(
[1] => Array
(
[0] => test
[1] => texts
)
[2] => texas
[6] => random
)
#Installation:
composer require v-bartusevicius/levenshtein-array-sort