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

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

enzyme/collection
=================

An all encompassing array manager.

v1.0.0(9y ago)1159MITPHPPHP &gt;=5.5.0

Since May 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/enzyme/collection)[ Packagist](https://packagist.org/packages/enzyme/collection)[ Docs](https://github.com/enzyme/collection)[ RSS](/packages/enzyme-collection/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (3)Versions (11)Used By (0)

Collection
==========

[](#collection)

[![Build Status](https://camo.githubusercontent.com/a65d9fba1333c92425fa4c0e3a78da2b367cbea099aa002d59307c99ea5ea2ba/68747470733a2f2f7472617669732d63692e6f72672f656e7a796d652f636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/enzyme/collection)[![Coverage Status](https://camo.githubusercontent.com/a78c2008c16ac820cb56c82a1e8d6354a2cfcc8336721afef3cec9948277d925/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f656e7a796d652f636f6c6c656374696f6e2f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/enzyme/collection?branch=develop)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/03bb621b335742e13a15413c983384f27b3bd36c6233bd2969df442bd9d8f70b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656e7a796d652f636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/enzyme/collection/?branch=master)[![StyleCI](https://camo.githubusercontent.com/a57ca428abc5b740af54829a659a37bf329cff60214da92738a2dc0247a60f44/68747470733a2f2f7374796c6563692e696f2f7265706f732f35393137383739362f736869656c64)](https://styleci.io/repos/59178796)

An all encompassing array manager.

Installation
============

[](#installation)

```
$ composer require enzyme/collection
```

Usage
=====

[](#usage)

You can create a collection from a standard PHP array. Once you have a collection, you can make use of all the methods it exposes.

```
use Acme\Mailer;
use Enzyme\Collection\Collection;

$users = new Collection(['John123', 'Jane456', 'Harry789']);

// Send each user an email.
$users->each(function ($user) {
    Mailer::sendWelcomeEmail($user);
});
```

The collection implements `ArrayAccess`, `Iterator` and `Countable`, so you can use it as a standard array.

```
use Enzyme\Collection\Collection;

$users = new Collection(['John123', 'Jane456', 'Harry789']);

var_dump($users[0]); // 'John123'
```

In the example above, the equivalent and much more readable method would be `$collection->first()`.

Available methods
=================

[](#available-methods)

Method signatureDescription`count()`Return the number of elements in the collection.`each(Closure $fn)`Execute the callback function provided on each item in the collection. The callback function is passed `$value, $key` as arguments. If the callback returns `false`, the function will return early and will not continue iterating over the remaining items left in the collection.`except(array $keys)`Return a new collection containing all the keys in the current collection except those whose keys match the ones provided.`filter(Closure $fn)`Return a new collection will all items that pass the given callback functions truth test.`first()`Get the value of the first item in the collection. If the collection is empty, a `CollectionException` will be thrown.`firstOrDefault($default = null)`Same as above, except instead of throwing an exception, return the provided default value.`get($key)`Get the value associated with the specified key. If the key does not exist, a `CollectionException` will be thrown.`getOrDefault($key, $default = null)`Same as above, except instead of throwing an exception, return the provided default value.`has($key, $value = null)`Checks whether the collection has the specified key, and/or key/value pair.`hasCount($min, $max = null)`Checks whether the collection has the minimum count specified, or a count that falls within the range specified.`isEmpty()`Whether the collection is empty.`keys()`Returns an array of all the keys used by the collection.`last()`Get the value of the last item in the collection. If the collection is empty, a `CollectionException` will be thrown.`lastOrDefault($default = null)`Same as above, except instead of throwing an exception, return the provided default value.`make(array $initial)` *static*Static helper method to instantiate a new collection. Useful for when you want to immediately chain a method. Eg: Collection::make(\[1, 2, 3\])-&gt;map(...)`map(Closure $fn)`Execute the callback function provided on each item in the collection. The callback function is passed `$value, $key` as arguments. The return value of the callback function will be saved into a new collection and that collection will be returned as a result`mapWithKey(Closure $fn)`Execute the given callback function for each element in this collection and save the results to a new collection with the specified key. The callback function should return a 1 element associative array, eg: \['key' =&gt; 'value'\] to be mapped.`only(array $keys)`Return a new collection containing only the items in the current collection whose keys match the ones provided.`pluck($pluck_key, $deep = true)`Grab and return a new collection will all values that have the specified `key`. By default, this will traverse multidimensional arrays.`push($value)`Return a new collection with the given value pushed onto a copy of the current collection's items.`pushArray(array $data)`Return a new collection with the given array pushed onto a copy of the current collection's items.`pushWithKey($key, $value)`Return a new collection with the given key/value pair pushed onto a copy of the current collection's items.`sort(Closure $fn)`Return a new collection after the user defined sort function has been executed on the items. Same callback function parameters as the PHP `usort` function.`toArray()`Returns the current collection as a standard PHP array.Contributing
============

[](#contributing)

Please see `CONTRIBUTING.md`

License
=======

[](#license)

MIT - Copyright (c) 2016 Tristan Strathearn, see `LICENSE`

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

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

Recently: every ~35 days

Total

9

Last Release

3548d ago

Major Versions

v0.0.8 → v1.0.02016-10-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/148afe40f056b8f57e43ed0505c6040f762e26805b1d1bebed87484d529bae07?d=identicon)[r3oath](/maintainers/r3oath)

---

Top Contributors

[![r3oath](https://avatars.githubusercontent.com/u/2805249?v=4)](https://github.com/r3oath "r3oath (16 commits)")

---

Tags

helperarraycollectionmanagementenzyme

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

23.8k69.4k](/packages/grumpydictator-firefly-iii)[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.3k443.7k14](/packages/aimeos-map)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4531.2M5](/packages/athari-yalinqo)[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38427.0k](/packages/bocharsky-bw-arrayzy)[spatie/array-functions

Some handy array helpers

24564.6k2](/packages/spatie-array-functions)[minwork/array

Pack of advanced array functions specifically tailored for: associative (assoc) array, multidimensional array, array of objects and handling nested array elements

63263.9k5](/packages/minwork-array)

PHPackages © 2026

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