PHPackages                             overtrue/double-array-trie - 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. overtrue/double-array-trie

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

overtrue/double-array-trie
==========================

A PHP implementation of Double Array Trie.

1.0.0(4y ago)12151MITPHPPHP &gt;=8.0.2CI passing

Since Apr 21Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/overtrue/double-array-trie)[ Packagist](https://packagist.org/packages/overtrue/double-array-trie)[ GitHub Sponsors](https://github.com/overtrue)[ RSS](/packages/overtrue-double-array-trie/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

DoubleArrayTrie
===============

[](#doublearraytrie)

> **⚠️ 注意 / Notice**
> **中文**: 此项目为练手项目，PHP 对于这种双数组数据结构的封装并不能带来理想的性能提升，不建议使用。
> **English**: This is a practice project. PHP's implementation of this double array data structure does not provide ideal performance improvements and is not recommended for production use.

[![Testing](https://github.com/overtrue/double-array-trie/actions/workflows/test.yml/badge.svg)](https://github.com/overtrue/double-array-trie/actions/workflows/test.yml)[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/09d1e9d26d8d2ed62aba8f31c6ec6793fcf26bb3a5716680aa433fedf3487ae4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6f766572747275652f6c61726176656c2d736f6369616c6974653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/09d1e9d26d8d2ed62aba8f31c6ec6793fcf26bb3a5716680aa433fedf3487ae4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6f766572747275652f6c61726176656c2d736f6369616c6974653f7374796c653d666c61742d737175617265)[![GitHub License](https://camo.githubusercontent.com/9370a160ca2767f8fab27fe4c41bcc40a9e6eb514d16da9f78221d39a31e2767/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f766572747275652f6c61726176656c2d736f6369616c6974653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/9370a160ca2767f8fab27fe4c41bcc40a9e6eb514d16da9f78221d39a31e2767/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f766572747275652f6c61726176656c2d736f6369616c6974653f7374796c653d666c61742d737175617265)[![Packagist Downloads](https://camo.githubusercontent.com/0c6af83f7ddac5c984169aa837c62fe6280f31d4771287f6fa5473be945b0ab3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f766572747275652f6c61726176656c2d736f6369616c6974653f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/0c6af83f7ddac5c984169aa837c62fe6280f31d4771287f6fa5473be945b0ab3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f766572747275652f6c61726176656c2d736f6369616c6974653f7374796c653d666c61742d737175617265)

A PHP implementation of Double Array Trie.

[![Sponsor me](https://github.com/overtrue/overtrue/raw/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)

Installing
----------

[](#installing)

```
$ composer require overtrue/double-array-trie -vvv
```

Usage
-----

[](#usage)

### Build a DoubleArrayTrie

[](#build-a-doublearraytrie)

#### build with a string array

[](#build-with-a-string-array)

```
use Overtrue\DoubleArrayTrie\Builder;

$builder = new Builder();

$trie = $builder->build(['foo', 'bar', 'baz']);

$trie->export()->toFile('trie.json');
$trie->export()->toFile('trie.php');
$trie->export()->toFile('trie.dat');
```

### build with a key-value array

[](#build-with-a-key-value-array)

```
use Overtrue\DoubleArrayTrie\Builder;

$builder = new Builder();

$trie = $builder->build([
            '一举' => 'yi ju',
            '一举一动' => 'yi ju yi dong',
        ]);
```

### Load a DoubleArrayTrie

[](#load-a-doublearraytrie)

```
use Overtrue\DoubleArrayTrie\Factory;

$trie = Factory::loadFromFile('trie.json');
$trie = Factory::loadFromFile('trie.php');
$trie = Factory::loadFromFile('trie.dat');
```

### Matching

[](#matching)

```
use Overtrue\DoubleArrayTrie\Matcher;

$trie = Factory::loadFromFile('trie.json');
$matcher = new Matcher($trie);
```

match a string no values:

```
// ['foo', 'bar', 'baz']

$matcher->match('foo'); // true
$matcher->match('oo'); // false
```

match a string with values:

```
// ['一举' => 'yi ju', '一举一动' => 'yi ju yi dong']

$matcher->match('一举'); // 'yi ju'
$matcher->match('一举一'); // false
```

### prefix matching

[](#prefix-matching)

```
// ['一举' => 'yi ju', '一举一动' => 'yi ju yi dong', '一举成名' => 'yi ju cheng ming',]
$matcher->prefixMatch('一举一动都很奇怪');
// [
//  '一举' => 'yi ju',
//  '一举一动' => 'yi ju yi dong'
//]
```

Credits
-------

[](#credits)

- [darts-java: Double-ARray Trie System Java implementation.](https://github.com/komiya-atsushi/darts-java)
- [DoubleArrayTrie: A PHP implementation of Double Array Trie.](https://linux.thai.net/~thep/datrie/)
- [双数组Trie树(DoubleArrayTrie)Java实现](https://www.hankcs.com/program/java/%E5%8F%8C%E6%95%B0%E7%BB%84trie%E6%A0%91doublearraytriejava%E5%AE%9E%E7%8E%B0.html)

❤️ Sponsor me
-------------

[](#heart-sponsor-me)

[![Sponsor me](https://github.com/overtrue/overtrue/raw/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)

如果你喜欢我的项目并想支持它，[点击这里 ❤️](https://github.com/sponsors/overtrue)

Project supported by JetBrains
------------------------------

[](#project-supported-by-jetbrains)

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

[![](https://camo.githubusercontent.com/3cf726e7cdadba47755b7f7ea4227945a92a2fa48aadf4a2573140ec6501c989/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a625f6265616d2e737667)](https://www.jetbrains.com/?from=https://github.com/overtrue)

Contributing
------------

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/vendor/package/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/vendor/package/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance43

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87% of commits — single point of failure

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

Unknown

Total

1

Last Release

1578d ago

### Community

Maintainers

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

---

Top Contributors

[![overtrue](https://avatars.githubusercontent.com/u/1472352?v=4)](https://github.com/overtrue "overtrue (20 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (3 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/overtrue-double-array-trie/health.svg)

```
[![Health](https://phpackages.com/badges/overtrue-double-array-trie/health.svg)](https://phpackages.com/packages/overtrue-double-array-trie)
```

###  Alternatives

[elvanto/litemoji

A PHP library simplifying the conversion of unicode, HTML and shortcode emoji.

894.9M14](/packages/elvanto-litemoji)

PHPackages © 2026

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