PHPackages                             selfiens/array2 - 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. selfiens/array2

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

selfiens/array2
===============

A fluent array utility

v1.0(1y ago)07MITPHPPHP &gt;=8.1

Since May 16Pushed 1y ago1 watchersCompare

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

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

Array2 - Immutable Array Helper for PHP
=======================================

[](#array2---immutable-array-helper-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/935c16a42aab1397f4742d7c390bd02d394ccdbe627061077d9db0d18523d409/68747470733a2f2f706f7365722e707567782e6f72672f73656c6669656e732f6172726179322f76)](//packagist.org/packages/selfiens/array2)[![Total Downloads](https://camo.githubusercontent.com/9d915eb6d9be0a883d51786b84f18f38eec0b84dc236c0b7c36a29fd3706b0fe/68747470733a2f2f706f7365722e707567782e6f72672f73656c6669656e732f6172726179322f646f776e6c6f616473)](//packagist.org/packages/selfiens/array2)[![License](https://camo.githubusercontent.com/351ee9e60d27953d245289e104310e669df92f65aa37836c8ed27c755ae184d9/68747470733a2f2f706f7365722e707567782e6f72672f73656c6669656e732f6172726179322f6c6963656e7365)](//packagist.org/packages/selfiens/array2)

A simple, immutable array helper class for PHP. It wraps PHP's native `ArrayObject` to provide convenient, chainable methods for common array operations, without modifying the original array.

Key Features
------------

[](#key-features)

- **Immutable:** The original array passed to the constructor is never changed. All manipulation methods return a *new* `Array2` instance with the modified data.
- **Fluent Interface:** Chain methods together for clear and expressive array transformations (e.g., `$array2->filter(...)->map(...)->get()`).
- **Extends `ArrayObject`:** Provides a familiar base and allows standard array access patterns if needed (though direct modification is discouraged to maintain immutability).
- **Common Operations:** Includes helpful methods like `filter`, `map`, `reduce`, `sort`, `find`, `first`, `last`, `keys`, `values`, `sum`, `merge`, `groupBySubkey`, and many more.
- **Type Hinted:** Uses PHP type hints for better code analysis and reliability.

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

[](#installation)

Install the package via Composer:

```
composer require selfiens/array2
```

Basic Usage
-----------

[](#basic-usage)

```

```

Immutability Explained
----------------------

[](#immutability-explained)

The core principle of `Array2` is **immutability**. When you call a method like `filter()` or `map()`, the original `Array2` object (and its underlying array) is **not** changed. Instead, a **new** `Array2` object containing the result of the operation is returned.

This approach helps prevent unintended side effects in your code, making it easier to reason about data flow and state changes.

Available Methods
-----------------

[](#available-methods)

`Array2` provides a range of methods for array manipulation, including:

- Filtering (`filter`, `filterNot`, `filterKeys`, `filterKeyValue`, `filterRecursive`, `valuesEq`, `valuesNotEq`, `removeValues`)
- Mapping (`map`, `mapKeyValue`)
- Reducing (`reduce`)
- Getting Data (`get`, `all`, `keys`, `values`, `valuesFlat`, `first`, `last`, `firstN`, `lastN`, `find`, `findKeyValue`)
- Sorting (`sort`, `sortNatural`, `sortNaturalCi`, `reverse`)
- Slicing &amp; Selection (`slice`, `onlyKeys`, `dropKeys`, `column`)
- Aggregation (`sum`, `average`, `min`, `max`, `count`)
- Modification-like (returning new instances) (`merge`, `mergeValues`, `replaceValue`, `unique`, `push`, `unshift`, `flip`, `valuesToKeys`)
- Utility (`join`, `tap` / `each`, `isAllTrue`, `isAnyTrue`, `intersect`, `diff`, `groupBySubkey`)

Please refer to the source code (`src/Array2.php`) for the full list of methods, their parameters, and detailed PHPDoc comments.

Testing
-------

[](#testing)

Run the included PHPUnit tests from the project root directory:

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

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

[](#contributing)

Contributions are welcome! Please feel free to submit pull requests or open issues on the GitHub repository.

License
-------

[](#license)

This project is licensed under the MIT License - see the `LICENSE` file for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance49

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

368d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/26b5b9575bb4504f1c1bf6bbf9b5c86a98f89585902220d9dbecbdc75e4a7f71?d=identicon)[selfiens](/maintainers/selfiens)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/selfiens-array2/health.svg)

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

###  Alternatives

[t3kit/t3kit

t3kit project. A TYPO3 website starterkit.

5624.3k](/packages/t3kit-t3kit)

PHPackages © 2026

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