PHPackages                             ulrichsg/php-collections - 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. ulrichsg/php-collections

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

ulrichsg/php-collections
========================

Collection classes for PHP 5.3

07PHP

Since Jul 17Pushed 12y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Collections Library for PHP
===========================

[](#collections-library-for-php)

PHP's arrays are a jack-of-all-trades data structure - highly flexible, but there are numerous use cases where I would rather have more specific functionality like the one offered by Java's Collection API. Since PHP 5, the [Standard PHP Library](http://php.net/manual/en/book.spl.php) offers classes that cover some of these cases, but not nearly all. This project is an attempt to add more.

What? Why?
----------

[](#what-why)

Imagine the following bit of code that aggregates values, indexed by type:

```
$totals = array();
foreach ($items as $item) {
	if (!isset($totals[$item->type])) {
		$totals[$item->type] = 0;
	}
	$totals[$item->type] += $item->value;
}
```

The `if (!isset(...))` block makes this piece of code rather ugly, but it is necessary to avoid even uglier warnings. Using the `NumberMap` class from this package we can avoid it and just write:

```
$totals = new NumberMap();
foreach ($items as $item) {
	$totals->add($item->type, $item->value);
}
```

Collection types
----------------

[](#collection-types)

So far the package only provides two collection types:

- `Map` - basic key-value map
- `NumberMap` - a map that can do some math on its entries (see the example above)

I'd love to have more, so send me your ideas - or your pull requests :)

Common features
---------------

[](#common-features)

For maximum convenience, all classes in this package implement the following interfaces:

- [ArrayAccess](http://php.net/manual/en/class.arrayaccess.php) - square-bracket syntax
- [IteratorAggregate](http://php.net/manual/en/class.iteratoraggregate.php) - foreach loops
- [Countable](http://www.php.net/manual/en/class.countable.php) - count() support

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

[](#installation)

- As a project dependency: Just add `ulrichsg/php-collections` to your composer.json.
- Stand-alone for hacking: Clone this repository and run `make` to see a few handy commands.

API documentation
-----------------

[](#api-documentation)

[Go here](http://ulrichsg.github.io/php-collections/doc) for PHPDoc-generated documentation.

License
-------

[](#license)

This package is released under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![ulrichsg](https://avatars.githubusercontent.com/u/197901?v=4)](https://github.com/ulrichsg "ulrichsg (2 commits)")

### Embed Badge

![Health badge](/badges/ulrichsg-php-collections/health.svg)

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

###  Alternatives

[hesammousavi/bootstrap-v4-rtl

boootstrap4 right to left

99128.1k](/packages/hesammousavi-bootstrap-v4-rtl)[nulpunkt/yesql-php

A clone of the wonderful yesql clojure library, for php

2512.5k](/packages/nulpunkt-yesql-php)

PHPackages © 2026

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