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

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

halfpastfouram/collection
=========================

A flexible PHP Collection complete with custom Iterator.

v1.0.0(9y ago)416.9k↑125%1[1 PRs](https://github.com/halfpastfouram/collection/pulls)3AGPL 3.0PHPPHP &gt;=5.6.0 || ^7.0

Since Dec 18Pushed 2y ago2 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (3)Used By (3)

[![Build Status](https://camo.githubusercontent.com/370bcbc1934786dcb7a2282915cadb36033292fe95b2c38eed6f12cfec5d69d2/68747470733a2f2f7472617669732d63692e6f72672f68616c6670617374666f7572616d2f636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/halfpastfouram/collection)[![Code Climate](https://camo.githubusercontent.com/96486fc8323120a439e437bb471146f13f324fac88fb591736028ef03e3e5bde/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f68616c6670617374666f7572616d2f636f6c6c656374696f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/halfpastfouram/collection)[![Test Coverage](https://camo.githubusercontent.com/06589bfc2689a2d44562cc2b9f44e0d42168bcfe71aa434d956e8915180f55c5/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f68616c6670617374666f7572616d2f636f6c6c656374696f6e2f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/halfpastfouram/collection/coverage)[![Downloads](https://camo.githubusercontent.com/fac2cdf797e2daf5947005908bd8a8b4d4bba70591aa9decce68850d47da9cba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68616c6670617374666f7572616d2f636f6c6c656374696f6e2e737667)](https://packagist.org/packages/halfpastfouram/collection)[![Latest Stable Version](https://camo.githubusercontent.com/8d93be7feaf8adf182b8e48c3819fc4c9b1ab46d069c67b8a2cb4a1b44ad1e9f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68616c6670617374666f7572616d2f636f6c6c656374696f6e2e737667)](https://packagist.org/packages/halfpastfouram/collection)

Mutable
=======

[](#mutable)

A flexible PHP Mutable complete with custom Iterator, part of the `halfpastfouram` code library.

What can you do with a collection?
----------------------------------

[](#what-can-you-do-with-a-collection)

A collection is a tool you can use to have a certain level of control over the data you store inside it. Where you could use an array in most situations a collection provides a more flexible way to deal with your data.

It is particularly useful to extend this class if you need to perform actions on a list of items or objects when they are added, removed, replaced or otherwise modified.

Control over collections
------------------------

[](#control-over-collections)

You can traverse all collection types. To give you more flexibility, use the `ArrayAccess` class which provides direct array access as if you were talking to an array. This class also provides an iterator that can be used in loops or even manually.

### Array access example

[](#array-access-example)

```
$collection = new Collection\ArrayAccess( [ 0, 1, 2, 3 ] );
$collection[] = 0;
$collection[5] = 12;
```

### Traversing

[](#traversing)

```
foreach( $collection as $key => $value ) {
    var_dump( $key, $value );
}
```

### Manual traversing (ArrayAccess only)

[](#manual-traversing-arrayaccess-only)

```
$iterator   = $collection->getIterator();

// Jump forward to next position
$iterator->next();
var_dump( $iterator->current() );

// Go back one position
$iterator->previous();
var_dump( $iterator->getKey(), $iterator->current() );

// Receive the list of keys in the dataset.
var_dump( $iterator->calculateKeyMap() );
```

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

[](#installation)

### Using composer

[](#using-composer)

```
$ composer require halfpastfouram/collection

```

### Development

[](#development)

This project uses composer, which should be installed on your system. Most Linux systems have composer available in their PHP packages. Alternatively you can download composer from [getcomposer.org](http://getcomposer.org).

If you use the PhpStorm IDE then you can simply init composer through the IDE. However, full use requires the commandline. See PhpStorm help, search for composer.

To start development, do `composer install` from the project directory.

**Remark** Do not use `composer update` unless you changed the dependency requirements in composer.json. The difference is that `composer install` will use composer.lock read-only, while `composer update` will update your composer.lock file regardless of any change. As the composer.lock file is committed to the repo, other developers might conclude dependencies have changed, while they have not.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3428d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1e70ec76c998aa9c17e4abcafa0134baab6c0ff640cd5025890eef61600eadb2?d=identicon)[bobkruithof](/maintainers/bobkruithof)

---

Top Contributors

[![halfpastfouram](https://avatars.githubusercontent.com/u/3202331?v=4)](https://github.com/halfpastfouram "halfpastfouram (34 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

collectioncomposer-packagelockphpphpcollection

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[jshannon63/jsoncollect

Supercharge your JSON using collections

154.9k1](/packages/jshannon63-jsoncollect)

PHPackages © 2026

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