PHPackages                             izica/php-collection - 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. izica/php-collection

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

izica/php-collection
====================

Tools and utilities for working with arrays

1.8.3(3y ago)3311MITPHPPHP &gt;=5.6.0

Since Mar 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/izica/php-collection)[ Packagist](https://packagist.org/packages/izica/php-collection)[ RSS](/packages/izica-php-collection/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)DependenciesVersions (20)Used By (0)

Php collection
==============

[](#php-collection)

inspired by Illuminate\\Support\\Collection and Lodash

### Usage

[](#usage)

```
composer require izica/php-collection

```

### Notice

[](#notice)

Every method will returns new collection, not mutated collection;

```
$collection = PhpCollection:collect([100, 200, 300, 400]);
$collection2 = $collection->filter(function($item){
    return $item > 200;
})

/*
    $collection != $collection2
*/
```

### Documentation

[](#documentation)

- [collect](#collectarray)
- [implode OR join](#implodearray----serializer---or-joinarray----serializer--)
- [pluck](#pluckkey)
- [only](#onlykeys)
- [exclude](#excludekeys)
- [filter](#filterfunctionitem)
- [map](#mapfunctionitem)
- [keyBy](#keybykey)
- [groupBy](#groupbykey)
- [find](#findfunctionitem)
- [some OR contains](#somefunctionitem-or-containsfunctionitem)
- [every](#everyfunctionitem)
- [sort](#sortfunctionitem)
- [values](#values)
- [first](#first)
- [last](#last)
- [count](#count)
- [all or toArray](#all-or-toarray)
- [toJson](#tojson)

#### collect($array, $isSingleElement = false)

[](#collectarray-issingleelement--false)

```
$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products);

// make collection from single element
$collection = PhpCollection:collect($products[0], true);
```

#### implode($array = ", ", $serializer = "") OR join($array = ", ", $serializer = "")

[](#implodearray----serializer---or-joinarray----serializer--)

```
$collection = PhpCollection:collect([100, "data", 300, 400])->implode();
/*
    100, data, 300, 400
*/

$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

// should return string
$serializer = function($item){
    return "{$item['name']}-{$item['price']}$"; // or for example -- return json_encode($item);
};

$collection = PhpCollection:collect($products)->implode(", ", $serializer);
/*
    product 1-100$, product 2-200$, product 3-300$
*/
```

#### pluck($key)

[](#pluckkey)

```
$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)->pluck("id")->all();
/*
    [1, 2, 3]
*/

$collection = PhpCollection:collect($products)->pluck("name")->all();
/*
    ["product 1", "product 2", "product 3"]
*/
```

#### only($keys)

[](#onlykeys)

```
$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)->only(["id", "name"])->all();
/*
[
    ["id" => 1, "name" => "product 1"],
    ["id" => 2, "name" => "product 2"],
    ["id" => 3, "name" => "product 3"]
]
*/

$collection = PhpCollection:collect($products)->only(["id", "name" => "title"])->all();

/*
[
    ["id" => 1, "title" => "product 1"],
    ["id" => 2, "title" => "product 2"],
    ["id" => 3, "title" => "product 3"]
]
*/
```

#### exclude($keys)

[](#excludekeys)

```
$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)->exclude(["name"])->all();

/*
[
    ["id" => 1, "price" => 100],
    ["id" => 2, "price" => 200],
    ["id" => 3, "price" => 300]
]
*/
```

#### filter(function($item))

[](#filterfunctionitem)

```
$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)
    ->filter(function($item){
        return $item["price"] > 100
    })
    ->all();

/*
[
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
]
*/
```

#### map(function($item))

[](#mapfunctionitem)

```
$products = [
    ["id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 3, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)
    ->map(function($item){
        $item["pricex2"] = $item["price"] * 2;
        return $item;
    })
    ->all();

/*
[
    ["id" => 1, "name" => "product 1", "price" => 100, "pricex2" => 200],
    ["id" => 2, "name" => "product 2", "price" => 200, "pricex2" => 400],
    ["id" => 3, "name" => "product 3", "price" => 300, "pricex2" => 600]
]
*/
```

#### keyBy($key | function($item))

[](#keybykey--functionitem)

```
$products = [
    ["id" => 16, "name" => "product 1", "price" => 100],
    ["id" => 22, "name" => "product 2", "price" => 200],
    ["id" => 31, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)->keyBy("id")->all();

/*
[
    16 => ["id" => 1, "name" => "product 1", "price" => 100, "pricex2" => 200],
    22 => ["id" => 2, "name" => "product 2", "price" => 200, "pricex2" => 400],
    31 => ["id" => 3, "name" => "product 3", "price" => 300, "pricex2" => 600]
]
*/
```

#### groupBy($key | function($item))

[](#groupbykey--functionitem)

```
$products = [
    ["id" => 16, "category_id" => 1, "name" => "product 1", "price" => 100],
    ["id" => 22, "category_id" => 2, "name" => "product 2", "price" => 200],
    ["id" => 31, "category_id" => 2, "name" => "product 3", "price" => 300]
];

$collection = PhpCollection:collect($products)->groupBy("category_id")->all();

/*
[
    1 => [
        ["id" => 16, "category_id" => 1, "name" => "product 1", "price" => 100]
    ],
    2 => [
        ["id" => 22, "category_id" => 2, "name" => "product 2", "price" => 200],
        ["id" => 31, "category_id" => 2, "name" => "product 3", "price" => 300]
    ]
]
*/
```

#### find(function($item))

[](#findfunctionitem)

#### some($value | function($item)) OR contains($value | function($item))

[](#somevalue--functionitem-or-containsvalue--functionitem)

#### every(function($item))

[](#everyfunctionitem)

#### sort(function($item))

[](#sortfunctionitem)

#### sortBy($key, $asc = true)

[](#sortbykey-asc--true)

#### values()

[](#values)

#### first()

[](#first)

#### last()

[](#last)

#### count()

[](#count)

#### all() OR toArray()

[](#all-or-toarray)

#### toJson()

[](#tojson)

#### zip()

[](#zip)

TODO
----

[](#todo)

#### dumpBrowser()

[](#dumpbrowser)

#### dump()

[](#dump)

#### toCsv()

[](#tocsv)

#### toXml()

[](#toxml)

#### shuffle()

[](#shuffle)

#### random()

[](#random)

#### chunk()

[](#chunk)

#### unique("" | $key | function($item))

[](#unique--key--functionitem)

#### collapse()

[](#collapse)

#### diff($array)

[](#diffarray)

#### has($key)

[](#haskey)

#### flip()

[](#flip)

#### min("" | $key | function($item))

[](#min--key--functionitem)

#### max("" | $key | function($item))

[](#max--key--functionitem)

#### reduce($function)

[](#reducefunction)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Recently: every ~335 days

Total

19

Last Release

1178d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d4a3945b13adc2ef1e9d7ef3a41c66e28706ae3229b85fc3696114eea990a46?d=identicon)[izica](/maintainers/izica)

---

Top Contributors

[![izica](https://avatars.githubusercontent.com/u/13401922?v=4)](https://github.com/izica "izica (36 commits)")

---

Tags

arrayarrayscollectioncollectionsilluminatelibrarylodashphpphp-arrayphp-collectionphp-libraryphp-lodashphp5php56php7tooltoolsutilitiesutilityutilsphparrayutilitytoolcollectioncollectionstoolsutilitiesarrays

### Embed Badge

![Health badge](/badges/izica-php-collection/health.svg)

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

###  Alternatives

[ilya/belt

A handful of tools for PHP developers.

70820.9k1](/packages/ilya-belt)[rotexsoft/versatile-collections

A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax or object property syntax.

186.1k1](/packages/rotexsoft-versatile-collections)

PHPackages © 2026

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