## eloquent/lcs

An implementation of the 'longest common subsequence' algorithm for PHP.

Installs: 8 141

Dependents: 0

Suggesters: 0

Security: 0

Stars: 16

Watchers: 3

Forks: 2

Open Issues: 2

Requires

- php: >=5.3

Requires (Dev)

- icecave/archer: ~1

This package is auto-updated.

Last update: 2020-08-06 05:50:34 UTC

# README

*An implementation of the 'longest common subsequence' algorithm for PHP.*

## Installation and documentation

- Available as Composer package eloquent/lcs.
- API documentation available.

## What is PHP-LCS?

*PHP-LCS* is a PHP implementation of an algorithm to solve the 'longest common
subsequence' problem.

From Wikipedia - longest common subsequence problem:

The

longest common subsequence (LCS) problemis to find the longest subsequence common to all sequences in a set of sequences (often just two). Note that subsequence is different from a substring, see substring vs. subsequence. It is a classic computer science problem, the basis of file comparison programs such as diff, and has applications in bioinformatics.

## Usage

use Eloquent\Lcs\LcsSolver; $solver = new LcsSolver; $sequenceA = array('B', 'A', 'N', 'A', 'N', 'A'); $sequenceB = array('A', 'T', 'A', 'N', 'A'); // calculates the LCS to be array('A', 'A', 'N', 'A') $lcs = $solver->longestCommonSubsequence($sequenceA, $sequenceB);

Elements in sequences can be anything. By default, sequence members are compared
using the `===`

operator. To customize this comparison, simply construct the
solver with a custom comparator, like so:

use Eloquent\Lcs\LcsSolver; $solver = new LcsSolver( function ($left, $right) { // return true if $left and $right are equal } );