2017 © Pedro PelĂĄez
 

library levenshtein-array-sort

Sorts haystack with strings by Levenshtein distance to needle

image

v-bartusevicius/levenshtein-array-sort

Sorts haystack with strings by Levenshtein distance to needle

  • Saturday, March 7, 2015
  • by v-bartusevicius
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

levenshtein-array-sort

Sorts given array of strings by Levenshtein distance., (*1)

Simply use:, (*2)

$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:, (*3)

Array
(
    [1] => test
    [2] => texas
    [6] => random
)

In case there are same distances to needle, the nested array will be created:, (*4)

$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, (*5)

The Versions

07/03 2015

dev-master

9999999-dev

Sorts haystack with strings by Levenshtein distance to needle

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.2

 

The Development Requires

by Valentinas Bartusevičius

array sort levenshtein