PHPackages                             nabeghe/matcher - 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. nabeghe/matcher

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

nabeghe/matcher
===============

A similar alternative to match in PHP for arrays, with a touch of zest.

v1.0.1(10mo ago)44MITPHPPHP &gt;=7.4

Since Oct 11Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/nabeghe/matcher-php)[ Packagist](https://packagist.org/packages/nabeghe/matcher)[ Docs](https://github.com/nabeghe/matcher-php)[ RSS](/packages/nabeghe-matcher/feed)WikiDiscussions master Synced 1mo ago

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

Matcher for PHP ≥ 7.4
=====================

[](#matcher-for-php--74)

> A similar alternative to match in PHP for arrays, with a touch of zest.

Extracting values and keys from an array with some variations in functionality.

🫡 Usage
-------

[](#-usage)

### 🚀 Installation

[](#-installation)

You can install the package via composer:

```
composer require nabeghe/matcher
```

### Example 1: Value

[](#example-1-value)

Similar to match in PHP 8.

```
use \Nabeghe\Matcher\Matcher;

$matched_value = Matcher::value([
    'key1' => 'value 1',
    'key2' => 'value 2',
    'key3' => 'value 3',
    'key4' => 'value 4',
    'key5' => 'value 5',
], 'key5');

echo $matched_value; // value 5
```

### Example 2: Default Value

[](#example-2-default-value)

Similar to match in PHP 8, with a default value in case the key doesn't exist.

```
use \Nabeghe\Matcher\Matcher;

$matched_value = Matcher::value([
    'key1' => 'value 1',
    'key2' => 'value 2',
    'key3' => 'value 3',
    'key4' => 'value 4',
    'key5' => 'value 5',
], 'key', 'value not found');

echo $matched_value; // value not found
```

### Example 3: Callable Value

[](#example-3-callable-value)

Similar to match in PHP 8, with the possibility of the value being callable.

```
$matched_value = Matcher::value([
    'key1' => 'value 1',
    'key2' => 'value 2',
    'key3' => 'value 3',
    'key4' => 'value 4',
    'key5' => function ($key) {
        return 'value 5';
    },
], 'key5', null, true);

echo $matched_value; // value 5
```

### Example 4: Key

[](#example-4-key)

Finding a key based on a value.

```
use \Nabeghe\Matcher\Matcher;

$matched_value = Matcher::key([
    'key1' => 'value 1',
    'key2' => 'value 2',
    'key3' => 'value 3',
    'key4' => 'value 4',
    'key5' => 'value 5',
], 'value 5');

echo $matched_value; // key5
```

### Example 5: Keys By Value

[](#example-5-keys-by-value)

Finding a set of keys based on a specific value.

```
use \Nabeghe\Matcher\Matcher;

$matched_value = Matcher::keys([
    'key1' => 'value 1',
    'key2' => 'value 2',
    'key3' => 'value 3',
    'key4' => 'value 4',
    'keys1' => 'value x',
    'keys2' => 'value x',
], 'value x');

print_r($matched_value); // keys1, keys2
```

### Example 6: Keys By Values

[](#example-6-keys-by-values)

Finding a set of keys based on a a set of values.

```
use \Nabeghe\Matcher\Matcher;

$matched_value = Matcher::keys([
    'key1' => 'value 1',
    'key2' => 'value 2',
    'key3' => 'value 3',
    'key4' => 'value 4',
    'key5' => 'value 5',
], ['value 1', 'value 5']);

print_r($matched_value); // key1, key5
```

📖 License
---------

[](#-license)

Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance54

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~264 days

Total

2

Last Release

320d ago

### Community

Maintainers

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

---

Top Contributors

[![nabeghe](https://avatars.githubusercontent.com/u/12207627?v=4)](https://github.com/nabeghe "nabeghe (3 commits)")

---

Tags

arraylibraryphpphplibraryarraylibraryMatchmatcher

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nabeghe-matcher/health.svg)

```
[![Health](https://phpackages.com/badges/nabeghe-matcher/health.svg)](https://phpackages.com/packages/nabeghe-matcher)
```

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[league/iso3166

ISO 3166-1 PHP Library

70036.3M116](/packages/league-iso3166)

PHPackages © 2026

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