PHPackages                             roukmoute/enumerable - 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. roukmoute/enumerable

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

roukmoute/enumerable
====================

Provides a set of methods for querying objects.

00PHP

Since Jul 17Pushed 7y ago2 watchersCompare

[ Source](https://github.com/roukmoute/enumerable)[ Packagist](https://packagist.org/packages/roukmoute/enumerable)[ RSS](/packages/roukmoute-enumerable/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Enumerable
==========

[](#enumerable)

Provides a set of methods for querying objects.
Enumerable is a collection library for PHP &gt;= 7.1 that implements most of the sequence operations proposed by [collection pipeline](http://martinfowler.com/articles/collection-pipeline/) object methods.

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

[](#installation)

Require this package using Composer.

`composer require roukmoute/enumerable`

Operation Catalog
-----------------

[](#operation-catalog)

Here is a catalog of the operations that you often find in collection pipelines :

### filter

[](#filter)

[![](https://camo.githubusercontent.com/490048e8c2bd90e77767c13486f7777f3be8d8d0fd1a1d9a080cd3b1bd6e5423/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f66696c7465722e706e67)](https://camo.githubusercontent.com/490048e8c2bd90e77767c13486f7777f3be8d8d0fd1a1d9a080cd3b1bd6e5423/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f66696c7465722e706e67)

Runs a boolean function on each element and only puts those that pass into the output.

You can use this function to keep only the items of the input you want to work with.
For example:

```
$query = (new \Enumerable\Enumerable([0, 30, 20, 15, 90, 85, 40, 75]))->filter(
    function ($number, $index) {
        return $number concat([4, 5]);

foreach ($query as $name) {
    echo $name . PHP_EOL;
}

// This code produces the following output:
//
// 1
// 2
// 3
// 4
// 5
```

If you want to concatenate more than two collections :

```
$query = (new \Enumerable\Enumerable([1, 2, 3]))->concat([4, 5])->concat([6]);

foreach ($query as $name) {
    echo $name . PHP_EOL;
}

// This code produces the following output:
//
// 1
// 2
// 3
// 4
// 5
// 6
```

### difference

[](#difference)

[![](https://camo.githubusercontent.com/1e13b95c897616bfad84aa0a0ac1527b4c29bd91f66588894f08334ac0709453/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f646966666572656e63652e706e67)](https://camo.githubusercontent.com/1e13b95c897616bfad84aa0a0ac1527b4c29bd91f66588894f08334ac0709453/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f646966666572656e63652e706e67)

Remove the contents of the supplied list from the pipeline

```
$query = (new \Enumerable\Enumerable([1, 1, 2, 2, 3, 4]))->difference([1, 3]);

foreach ($query as $number) {
    echo $number . PHP_EOL;
}

// This code produces the following output:
//
// 2
// 2
// 4
```

### distinct

[](#distinct)

[![](https://camo.githubusercontent.com/78c2f53000668c6f6241f17e0a8c1fbfb48308c87e5186027c95d71f0939fb2e/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f64697374696e63742e706e67)](https://camo.githubusercontent.com/78c2f53000668c6f6241f17e0a8c1fbfb48308c87e5186027c95d71f0939fb2e/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f64697374696e63742e706e67)

Removes duplicate elements

Returns a new list with any duplicates removed.

```
$query = (new \Enumerable\Enumerable([1, 2, 3, 2, 1]))->distinct();

foreach ($query as $number) {
    echo $number . PHP_EOL;
}

// This code produces the following output:
//
// 1
// 2
// 3
```

### slice

[](#slice)

[![](https://camo.githubusercontent.com/8ea81c05822179550197bb62662aeec24e02554aed7d07855dc29be39160d59a/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f736c6963652e706e67)](https://camo.githubusercontent.com/8ea81c05822179550197bb62662aeec24e02554aed7d07855dc29be39160d59a/68747470733a2f2f6d617274696e666f776c65722e636f6d2f61727469636c65732f636f6c6c656374696f6e2d706970656c696e652f636f6c6c656374696f6e2d706970656c696e652f736c6963652e706e67)

Return a sub-sequence of the list between the given first and last positions.

If you want some of the list, you can take a slice of the list.

```
$query = (new \Enumerable\Enumerable([1, 2, 3, 4, 5, 6]))->slice(2, 4);

foreach ($query as $number) {
    echo $number . PHP_EOL;
}

/**
 * This code produces the following output:
 *
 * 3
 * 4
 * 5
 */
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

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.

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/roukmoute-enumerable/health.svg)

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

###  Alternatives

[rlanvin/php-ip

IPv4/IPv6 manipulation library for PHP

180738.8k11](/packages/rlanvin-php-ip)[pagerfanta/core

Core Pagerfanta API

487.9M24](/packages/pagerfanta-core)[php-slang/php-slang

PHPSlang is a library that allow you to write a purely functional code in PHP

10627.2k2](/packages/php-slang-php-slang)[bisight/etl

BiSight ETL: Extract, Transform, Load toolkit

124.1k](/packages/bisight-etl)

PHPackages © 2026

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