WooCommerce Code Reference

LexicalDistance
in package

Computes the lexical distance between strings A and B.

The "distance" between two strings is given by counting the minimum number of edits needed to transform string A into string B. An edit can be an insertion, deletion, or substitution of a single character, or a swap of two adjacent characters.

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.

This distance can be useful for detecting typos in input or sorting

Unlike the native levenshtein() function that always returns int, LexicalDistance::measure() returns int|null. It takes into account the threshold and returns null if the measured distance is bigger.

Table of Contents

$input  : string
$inputArray  : array<string|int, mixed>
List of char codes in the input string.
$inputLowerCase  : string
__construct()  : mixed
measure()  : int|null
stringToArray()  : array<string|int, int>
Returns a list of char codes in the given string.

Properties

Methods

stringToArray()

Returns a list of char codes in the given string.

private static stringToArray(string $str) : array<string|int, int>
Parameters
$str : string
Return values
array<string|int, int>