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

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

phpextra/collection
===================

Collection type for PHP

27.5k[3 issues](https://github.com/phpextra/collection/issues)PHP

Since Apr 2Pushed 11y ago1 watchersCompare

[ Source](https://github.com/phpextra/collection)[ Packagist](https://packagist.org/packages/phpextra/collection)[ RSS](/packages/phpextra-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

\#Collection (PHPExtra\\Type\\Collection)

[![Latest Stable Version](https://camo.githubusercontent.com/9e949836f43cbb2965ea516f844a616df353a549f2a4c23b764fcd8e21aed98d/68747470733a2f2f706f7365722e707567782e6f72672f70687065787472612f636f6c6c656374696f6e2f762f737461626c652e737667)](https://packagist.org/packages/phpextra/collection)[![Total Downloads](https://camo.githubusercontent.com/9567932d457000fb8871c58dbcca2b530b6a8dd5f995931360fef8db1b83686d/68747470733a2f2f706f7365722e707567782e6f72672f70687065787472612f636f6c6c656374696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/phpextra/collection)[![License](https://camo.githubusercontent.com/f8a7e53a7e60b4043e95d046b0a2d93ad7ccf26e7dd8f4c630184039458626c8/68747470733a2f2f706f7365722e707567782e6f72672f70687065787472612f636f6c6c656374696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/phpextra/collection)[![Build Status](https://camo.githubusercontent.com/874b73416b529c44935fa634396582d3b6834c512474a13e679180154aad3d33/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f70687065787472612f636f6c6c656374696f6e2e737667)](https://travis-ci.org/phpextra/collection)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2a2936e86b6a778f56679f75f6b1b8a93078a26188d6401b2a1aec6ce316d674/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70687065787472612f636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpextra/collection/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/e97ace878c2e338f38d5e4761f8f65b43dc2ddab4243316e0a9cef382615d419/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70687065787472612f636f6c6c656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpextra/collection/?branch=master)[![GitTip](https://camo.githubusercontent.com/0ec766cd3550cb42f0db394a3dc81c594379aba38bdca4d1b31a56d9baae78c3/687474703a2f2f696d672e736869656c64732e696f2f6769747469702f6a6b6f6275732e737667)](https://www.gittip.com/jkobus)

\##Usage

Collection solve few things by implementing following interfaces: `\Countable`, `\ArrayAccess`, `\Iterator`, and `\SortableInterface`. This gives you an ability to `count()` collection, use a `foreach` on it, access it like an array `$a[1]` and sort its contents `$a->sort($sorter)`. Apart from regular collections there are also `LazyCollection`'s that allow you to specify a closure that will initialize collection contents only if it's needed.

Create your first collection:

```
$collection = new Collection();

$collection->add('item1');
$collection->add('item2');
$collection->add('item3');
```

Use it:

```
echo count($collection); // returns 3
echo $collection[0]; // returns "item1"
echo $collection->slice(1, 2); // returns Collection with a length of 2 containing item2 and item3.
echo $collection->filter(function($element, $offset){ return $offset % 2 == 0; }); // returns sub-collection with all elements with even offset number
$collection->sort(SorterInterface $sorter); // sorts collection
```

Lazy collection example:

```
$lazy = new LazyCollection(function(){
    return new Collection(array(1, 2, 3));
});

echo $lazy[2]; // initializes the closure and returns "3"
```

Installation (Composer)
-----------------------

[](#installation-composer)

```
{
    "require": {
        "phpextra/collection":"~1.0"
    }
}
```

\##Changelog

```
No releases yet

```

\##Contributing

All code contributions must go through a pull request. Fork the project, create a feature branch, and send me a pull request. To ensure a consistent code base, you should make sure the code follows the [coding standards](http://symfony.com/doc/2.0/contributing/code/standards.html). If you would like to help take a look at the **list of issues**.

\##Requirements

```
See composer.json for a full list of dependencies.

```

\##Authors

```
Jacek Kobus -

```

License information
-------------------

[](#license-information)

```
See the file LICENSE.txt for copying permission.on.

```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.7% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1527096?v=4)[Jacek](/maintainers/jkobus)[@jkobus](https://github.com/jkobus)

---

Top Contributors

[![jkobus](https://avatars.githubusercontent.com/u/1527096?v=4)](https://github.com/jkobus "jkobus (11 commits)")[![ramonacat](https://avatars.githubusercontent.com/u/303398?v=4)](https://github.com/ramonacat "ramonacat (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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