PHP string levenshtein() Function

PHP string levenshtein() function is in-built function. It is used to calculate the distance between two strings. By default, PHP provides some operations (replace, insert and delete)

It returns the Levenshtein distance between the two argument strings or -1, if the string exceeds 255 characters.

Syntax:

ParameterDescriptionRequired/Optional
String1Specify first string to compare.required
String2Specify second string to compare.required
cost_insSpecify the cost insertion.Optional
cost_repSpecify the cost of replacement.Optional
cost_delSpecify the cost of deletion.Optional

Note: The levenshtein() function is not case-sensitive language.

Example 1

Output:

1

Example 2

Output:

2

Example 3

Output:

30

Example 4

Output:

10

Next TopicPHP String




Latest Courses