PHPackages                             triun/longest-common-subsequence - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. triun/longest-common-subsequence

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

triun/longest-common-subsequence
================================

PHP implementation of an algorithm to solve the 'longest common subsequence' problem.

1.1.0(8y ago)110.3k↑1463.3%1MITPHPPHP &gt;=7.0.0

Since Apr 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Triun/PHP-Longest-Common-Subsequence)[ Packagist](https://packagist.org/packages/triun/longest-common-subsequence)[ Docs](https://github.com/Triun)[ RSS](/packages/triun-longest-common-subsequence/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

PHP - Longest Common Subsequence
================================

[](#php---longest-common-subsequence)

PHP implementation of an algorithm to solve the `longest common subsequence` problem.

[![Latest Version on Packagist](https://camo.githubusercontent.com/88c119d2c6aec0c51f6d188e2273c704569bb1eeb0e0f8ec587d79c4fb02634b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747269756e2f6c6f6e676573742d636f6d6d6f6e2d73756273657175656e63652e737667 "Stable version")](https://packagist.org/packages/triun/longest-common-subsequence)[![Build Status](https://camo.githubusercontent.com/c0682d84c5e1e6849866af86b1ba203b0a4361390c04b3ca30aa5acb70c03bcd/68747470733a2f2f7472617669732d63692e6f72672f547269756e2f5048502d4c6f6e676573742d436f6d6d6f6e2d53756273657175656e63652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Triun/PHP-Longest-Common-Subsequence)[![Coverage status](https://camo.githubusercontent.com/1705ba283d2d914578ab944e848025ddffacf5cc73adccc4e285bda7628e64e0/68747470733a2f2f636f6465636f762e696f2f67682f547269756e2f5048502d4c6f6e676573742d436f6d6d6f6e2d53756273657175656e63652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Triun/PHP-Longest-Common-Subsequence)[![Total Downloads](https://camo.githubusercontent.com/3002ec515008bb102f7478826aca4b2f8719797e891e038121b2b89aa2198f59/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f747269756e2f6c6f6e676573742d636f6d6d6f6e2d73756273657175656e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/triun/longest-common-subsequence)[![The most recent stable version is 2.0.0](https://camo.githubusercontent.com/14292701dabbd874c065e08be17dde83a526fb7d21a7874f6d068c1467bc4554/687474703a2f2f696d672e736869656c64732e696f2f3a73656d7665722d322e302e302d627269676874677265656e2e737667 "This project uses semantic versioning")](http://semver.org/)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

About
=====

[](#about)

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

From [Wikipedia - Longest common subsequence problem](https://en.wikipedia.org/wiki/Longest_common_subsequence_problem):

> The *longest common subsequence (LCS) problem* is the problem of finding the longest [subsequence](https://en.wikipedia.org/wiki/Subsequence) common to all sequences in a set of sequences (often just two sequences). It differs from the [longest common substring problem](https://en.wikipedia.org/wiki/Longest_common_substring_problem): unlike substrings, subsequences are not required to occupy consecutive positions within the original sequences. The longest common subsequence problem is a classic [computer science](https://en.wikipedia.org/wiki/Computer_science) problem, the basis of [data comparison](https://en.wikipedia.org/wiki/Data_comparison) programs such as the [diff utility](https://en.wikipedia.org/wiki/Diff_utility), and has applications in [bioinformatics](https://en.wikipedia.org/wiki/Bioinformatics). It is also widely used by [revision control systems](https://en.wikipedia.org/wiki/Revision_control) such as [Git](https://en.wikipedia.org/wiki/Git_(software)) for [reconciling](https://en.wikipedia.org/wiki/Merge_(revision_control)) multiple changes made to a revision-controlled collection of files.

This PHP implementation is based on [eloquent/php-lcs](https://github.com/eloquent/php-lcs), adding a little more flexibility in order to handle, not only the common text, but also the differences.

Installation
============

[](#installation)

Require [triun/longest-common-subsequence package](https://packagist.org/packages/triun/longest-common-subsequence) with [composer](http://getcomposer.org/)using the following command:

```
composer require triun/longest-common-subsequence
```

Usage
=====

[](#usage)

```
use Triun\LongestCommonSubsequence\Solver;

$solver = new Solver;

$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->solve($sequenceA, $sequenceB);
```

Issues
======

[](#issues)

Bug reports and feature requests can be submitted on the [Github Issue Tracker](https://github.com/Triun/PHP-Longest-Common-Subsequence/issues).

Contributing
============

[](#contributing)

See [CONTRIBUTING.md](CONTRIBUTING.md) for information.

License
=======

[](#license)

This repository is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Total

2

Last Release

2966d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f12f0a4945103bdb3f1e3e53a229dfe0f603ba4a70a0728aa929475052f051ef?d=identicon)[gonzalom](/maintainers/gonzalom)

---

Tags

lcslongest-common-subsequencesubsequence

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/triun-longest-common-subsequence/health.svg)

```
[![Health](https://phpackages.com/badges/triun-longest-common-subsequence/health.svg)](https://phpackages.com/packages/triun-longest-common-subsequence)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
