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

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

ballen/collection
=================

A Collection library which provides OOP replacement for the traditional array data structure.

2.0.3(3y ago)3860.4k↓40.2%3[1 PRs](https://github.com/allebb/collection/pulls)5MITPHPPHP ^7.3.0|^8.0CI failing

Since Jul 2Pushed 4mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (13)Used By (5)

Collection
==========

[](#collection)

[![Build](https://github.com/allebb/collection/workflows/build/badge.svg)](https://github.com/allebb/collection/actions)[![Code Coverage](https://camo.githubusercontent.com/5bbbee8685dcf581b1511c7272cfedd07e3831c5bbaa7cebd3268e7418f314b1/68747470733a2f2f636f6465636f762e696f2f67682f616c6c6562622f636f6c6c656374696f6e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/allebb/collection)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8baccab1198b66a5225eeb415cf6ec9f1340826b00906b47374f901c25db560c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f616c6c6562622f636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/allebb/collection/?branch=master)[![Code Climate](https://camo.githubusercontent.com/a5606374b9567d3026248d73e5fe70263cd9e48d17661950f44538bc23420662/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f616c6c6562622f636f6c6c656374696f6e2f6261646765732f6770612e737667)](https://codeclimate.com/github/allebb/collection)[![Latest Stable Version](https://camo.githubusercontent.com/43f8447131c8f4adb3f4a343a8a24470f030e9178d1913e9b2bc899bb7795eed/68747470733a2f2f706f7365722e707567782e6f72672f62616c6c656e2f636f6c6c656374696f6e2f762f737461626c65)](https://packagist.org/packages/ballen/collection)[![Latest Unstable Version](https://camo.githubusercontent.com/eb9de251d94edeae454041277016a1c9dee51400a57197c7c53b36c800c4106e/68747470733a2f2f706f7365722e707567782e6f72672f62616c6c656e2f636f6c6c656374696f6e2f762f756e737461626c65)](https://packagist.org/packages/ballen/collection)[![License](https://camo.githubusercontent.com/3c5883d18327da91f1337afb7ce676976b7844905081be7ba273e04ee52ecaac/68747470733a2f2f706f7365722e707567782e6f72672f62616c6c656e2f636f6c6c656374696f6e2f6c6963656e7365)](https://packagist.org/packages/ballen/collection)

This Collection library is an OOP replacement for the traditional array data structure. Much like an array, a collection contains member elements, although these tend to be objects rather than simpler types such as strings and integers.

This library is developed and maintained by myself for various personal projects where I don't want to rely on third-party collection packages for licensing reasons or maintainability etc.

Requirements
------------

[](#requirements)

This library is developed and tested for PHP 7.3+

This library is unit tested against PHP 7.3, 7.4, 8.0, 8.1 and 8.2!

If you need to use an older version of PHP, you should instead install the 1.x version of this library (see below for details).

License
-------

[](#license)

This client library is released under the MIT license, a [copy of the license](https://github.com/allebb/collection/blob/master/LICENSE) is provided in this package.

Setup
-----

[](#setup)

To install the latest version of this package into your project (assuming you are using the Composer package manager) you can simply execute the following command from your terminal in the root of your project folder:

```
composer require ballen/collection
```

**If you need to use an older version of PHP, version 1.x.x supports PHP 5.6, 7.0, 7.1 and 7.2, you can install this version using Composer with this command instead:**

```
composer require ballen/collection ^1.0
```

Usage
-----

[](#usage)

A simple example of adding, sorting and iterating data in a collection.

```
