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

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

vk-php-utils/chain
==================

PHP Chain library

1.0.11(4y ago)213.5k↓82.6%MITPHPPHP &gt;=7.4CI failing

Since Nov 16Pushed 2y agoCompare

[ Source](https://github.com/kustov-vitalik/php-utils-chain)[ Packagist](https://packagist.org/packages/vk-php-utils/chain)[ RSS](/packages/vk-php-utils-chain/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (13)Used By (0)

PHP Chain Library
=================

[](#php-chain-library)

[![Build Status](https://camo.githubusercontent.com/81f751e1b10eb9c534d97b459cba3e12b715ff7ed663a956af3b4192df54efb2/68747470733a2f2f7472617669732d63692e6f72672f6b7573746f762d766974616c696b2f7068702d7574696c732d636861696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kustov-vitalik/php-utils-chain)[![Latest Stable Version](https://camo.githubusercontent.com/d8f37d1cb7ceb6618c828478198f183a33ca43fbd3b1930e628da43892852ceb/68747470733a2f2f706f7365722e707567782e6f72672f766b2d7068702d7574696c732f636861696e2f762f737461626c65)](https://packagist.org/packages/vk-php-utils/chain)[![Coverage Status](https://camo.githubusercontent.com/e16a09f9665401449d5e1f79d6c3eab0a027145c5d3852ef9264bb95f4dc644c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6b7573746f762d766974616c696b2f7068702d7574696c732d636861696e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/kustov-vitalik/php-utils-chain?branch=master)[![Latest Unstable Version](https://camo.githubusercontent.com/a56ed091dcb50a6be15f524867cc0fbc146367e4d6cd654e63c87f19ad2fe5ee/68747470733a2f2f706f7365722e707567782e6f72672f766b2d7068702d7574696c732f636861696e2f762f756e737461626c65)](https://packagist.org/packages/vk-php-utils/chain)[![Total Downloads](https://camo.githubusercontent.com/fa03c4eac8d46d64b13209a7e69f57fd4989a300fe664a7c3c7da6bf95b633db/68747470733a2f2f706f7365722e707567782e6f72672f766b2d7068702d7574696c732f636861696e2f646f776e6c6f616473)](https://packagist.org/packages/vk-php-utils/chain)[![License](https://camo.githubusercontent.com/31e78d9e33029abf91273d66ab1681228cd7d8d612b70b52d8c78701df00b116/68747470733a2f2f706f7365722e707567782e6f72672f766b2d7068702d7574696c732f636861696e2f6c6963656e7365)](https://packagist.org/packages/vk-php-utils/chain)[![composer.lock](https://camo.githubusercontent.com/fa0bb83fec5f7d9b831b70dd62450ff1ae8056e802a642b27e1cd0d6cfab4c34/68747470733a2f2f706f7365722e707567782e6f72672f766b2d7068702d7574696c732f636861696e2f636f6d706f7365726c6f636b)](https://packagist.org/packages/vk-php-utils/chain)

The library was created to make working with collections more simple in PHP

Requirements
------------

[](#requirements)

- PHP &gt;=7.4 (PHP 8.1 is supported)
- Extensions: json, mbstring

Installation
------------

[](#installation)

```
composer require vk-php-utils/chain:^1.0
```

Chain API
---------

[](#chain-api)

```
use VKPHPUtils\Chain\Chain;

// Constructors
Chain::of(...$items): Chain          // Initialize mutable chain
Chain::immutable(...$items): Chain   // Initialize immutable chain

// API
toArray(): array;   // Converts the chain to array (applies all chain-functions)
toChain(): Chain;   // Useful with mutable chain. Returns new chain with all current chain functions applied

hasKey($key): bool              // Check exists the key in current chain or no
hasValue($value): bool;         // Check existence of the value in the chain
search($value)                  // Searches position (key) of the value in current chain. Returns null if the value not found
getValue($key)                  // Get value using key
setValue($key, $value): Chain;  // Set value using key
remove($key): Chain;            // Removes element with index eq to $key
isEmpty(): bool                 // Check is the chain empty
size(): int                     // Get the chain size (number of elements)
count(): int                    // Get the chain size (number of elements)
append($any): Chain;            // Appends value into the chain
prepend($any): Chain;           // Prepend value into the chain

// map/reduce methods
filter(?callable $fn = null): Chain         // Filter the chain using function $fn
map(callable $fn): Chain;                   // Applies function $fn to each chain item and returns chain with mapped entities. Index-safe operation
flatMap(callable $fn): Chain;               // Works like {@see map()} but returns iterable set of mapped objects per each the chain's item
reduce(callable $fn, $initialValue = null)  // Calculate aggregate function result

// keys/values
keys(): Chain;                              // Get keys of the chain
values(): Chain;                            // Get chain values

// chain methods
diff(...$elements): Chain;                  // Calculates diff between current chain and passed one
merge(...$elements): Chain;                 // Merges all elements with current chain
intersect(...$elements): Chain;             // Calculates intersection of two sets (current chain and passed one). Non index-safe operation
intersectKeepIndexes(...$elements): Chain;  // Calculates intersection of two sets (current chain and passed one). Index-safe operation
frequencyAnalysis(): Chain;                 // Created histogram/frequency analysis of the chain
flip(): Chain;                              // Flip the chain
mix(): Chain;                               // Mixes the chain
reverse(bool $saveIndex = false): Chain;    // Reverse current chain
unique(bool $saveIndex = false): Chain;     // Unique items of current chain
slice(int $startIncluded, int $stopExcluded, int $step = 1, bool $saveIndex = false): Chain;                // Get chain's chunk
forEach(callable $fn): Chain;               // Just calls $fn for each chain element

// sort methods
sortKeys(?callable $sortFn = null, ?int $direction = SORT_ASC, ?int $sortFlags = null): Chain;              // Sorts chain by keys
sortValues(?callable $sortFn = null, ?int $direction = SORT_ASC, ?int $sortFlags = SORT_REGULAR): Chain;    // Sorts chain by values. Index-safe operation
sortByProperty(string $propertyName, int $direction = SORT_ASC): Chain;                                     // Sorts collection by given property
```

Run Tests
---------

[](#run-tests)

`./vendor/bin/phpunit ./tests`

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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 ~79 days

Recently: every ~211 days

Total

12

Last Release

1553d ago

PHP version history (3 changes)1.0.0PHP ^7.3

1.0.4PHP ^7.4

1.0.9PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1487558?v=4)[Vitaly Kustov](/maintainers/kustov-vitalik)[@kustov-vitalik](https://github.com/kustov-vitalik)

---

Top Contributors

[![kustov-vitalik](https://avatars.githubusercontent.com/u/1487558?v=4)](https://github.com/kustov-vitalik "kustov-vitalik (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/ux-autocomplete

JavaScript Autocomplete functionality for Symfony

645.9M39](/packages/symfony-ux-autocomplete)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k18](/packages/solspace-craft-freeform)[api-platform/symfony

Symfony API Platform integration

384.5M127](/packages/api-platform-symfony)[symfony/ai-platform

PHP library for interacting with AI platform provider.

521.4M283](/packages/symfony-ai-platform)[api-platform/serializer

API Platform core Serializer

274.8M85](/packages/api-platform-serializer)

PHPackages © 2026

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