PHPackages                             formigone/php-chain - 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. formigone/php-chain

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

formigone/php-chain
===================

v0.1.1(9y ago)914.4k1MITPHPPHP &gt;=5.3.3

Since Feb 3Pushed 9y agoCompare

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

READMEChangelogDependencies (1)Versions (8)Used By (0)

\#php-chain

> A thin abstraction over PHP arrays to help you easily chain array transformation functions.

### What problems does this library solve?

[](#what-problems-does-this-library-solve)

The goal of this simple library is to help you work with arrays in PHP, particularly when using multiple of the transformation functions for arrays.

### Examples:

[](#examples)

Suppose you have an array of arrays such as the following:

```
    $users = array(
        array(
            'id' => 4,
            'username' => 'jshep',
            'firstName' => 'Jack',
            'lastName' => 'Shepherd',
            'active' => true
         ),
        array(
            'id' => 8,
            'username' => 'jlock',
            'firstName' => 'John',
            'lastName' => 'Lock',
            'active' => false
         ),
        // ...
        array(
            'id' => 23,
            'username' => 'jj-jacob',
            'firstName' => 'Jacob',
            'lastName' => null,
            'active' => false
        ),
        array(
            'id' => 42,
            'username' => 'smokey',
            'firstName' => 'Esau',
            'lastName' => 'Iratus',
            'active' => true
        ),
    );
```

With that on hand, you may want to `map` over that array, then `filter` it, and possibly `diff` those objects against an identical or similar collection representing the same data models.

```
    $activeUsers = array_filter($users, function($user) {
          return $user['active'];
    });

    $activeUsernames = array_map(function($user) {
          return $user['username'];
    }, $activeUsers);
```

One problem you've noticed if you've ever had to use some of PHP's array functions is that the order of the arguments is not consistent. Does the predicate function go before or after the array?

The other problem php-chain aims to solve is to using these functions more terse, and without dropping those intermediary collections along the way.

```
    $activeUsernames = Formigone\Chain::from($users)
         ->filter(function($user){ return $user['active']; })
         ->map(function($user){ return $user['username']; })
         ->get();
```

### Supported functionality

[](#supported-functionality)

- `map($predicateFunction)` - projects the current array into the output of the predicate function
- `filter($predicateFunction)` - filters the current array with the predicate function
- `reduce($predicateFunction, $optInitialValue)` - reduces the current array into a value generated by the predicate function
- `intersect($predicateFunction, $otherArray)` - iterates the current array with each element from the other array, keeping values found in both arrays (whenever the predicate function returns true)
- `diff($predicateFunction, $otherArray)` - iterates the current array with each element from the other array, keeping values unique to the current array (whenever the predicate function returns false)
- `flip()` - returns the current array flipping keys and values (not destroying the current array)
- `get()` - returns a copy of the current array

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.4% 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 ~67 days

Recently: every ~88 days

Total

7

Last Release

3356d ago

### Community

Maintainers

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

---

Top Contributors

[![formigone](https://avatars.githubusercontent.com/u/852234?v=4)](https://github.com/formigone "formigone (17 commits)")[![wolfy-j](https://avatars.githubusercontent.com/u/796136?v=4)](https://github.com/wolfy-j "wolfy-j (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/formigone-php-chain/health.svg)

```
[![Health](https://phpackages.com/badges/formigone-php-chain/health.svg)](https://phpackages.com/packages/formigone-php-chain)
```

###  Alternatives

[saad-tazi/g-chart-bundle

A super simple Bundle that facilitate the usage of Google Chart Tool, Google Chart Image API and Google Infographics.

20167.1k](/packages/saad-tazi-g-chart-bundle)[felixdorn/laravel-rickroll

Rickrolls people trying to break your site.

867.3k](/packages/felixdorn-laravel-rickroll)[alexanderschnitzler/phpstorm.meta.php-typo3

This package contains a .phpstorm.meta.php file which can be used to ease the work with TYPO3 projects in phpstorm.

2157.4k](/packages/alexanderschnitzler-phpstormmetaphp-typo3)[jenky/laravel-plupload

Plupload package for Laravel 5

2919.5k](/packages/jenky-laravel-plupload)

PHPackages © 2026

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