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

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

fusion-php/collection
=====================

A small collection library for PHP 7.4+

3.0.0(5y ago)11.2k[1 PRs](https://github.com/FusionPHP/collection/pulls)MITPHPPHP &gt;=7.4CI passing

Since Apr 22Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/FusionPHP/collection)[ Packagist](https://packagist.org/packages/fusion-php/collection)[ Docs](https://github.com/FusionPHP/collection)[ RSS](/packages/fusion-php-collection/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (7)Used By (0)

Fusion.Collection
=================

[](#fusioncollection)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2832f4fc2c5236616d9c8804ec1463fcbae81276550ad35a16508b0cac61f893/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f467573696f6e5048502f636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FusionPHP/collection/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/7f57a531783ead1f69723c9c833cc71b76044df3b4eb3885b254a57b035edbe5/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f467573696f6e5048502f636f6c6c656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/FusionPHP/collection/?branch=master)[![Build Status](https://camo.githubusercontent.com/b8d7d442e79a4f0f13c6da9068b7b820d12dd774c98640abcbb673f81233b5a4/68747470733a2f2f7472617669732d63692e636f6d2f467573696f6e5048502f636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/FusionPHP/collection)

This package provides a small collection library useful for aggregating data values in an object. Stored values can be accessed via methods, loops, or as an array.

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

[](#requirements)

PHP 7.4 or greater.

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

[](#installation)

This package is installed via Composer.

```
composer require fusion-php/collection

```

Usage
-----

[](#usage)

The library provides two different types of a collection. A basic object, simply `Collection`, and a `Dictionary`. There are two variants of these called `TypedCollection` and `TypedDictionary`which are meant for storing instances of specific object types.

### Instantiation

[](#instantiation)

Creating any of the collection objects this library provides can be done via constructor or with the `CollectionFactory` class. The remainder of this section will assume the usage of the `CollectionFactory` class to create collection objects. For information about instantiation via constructor please see the [Manual Instantiation](#manual_instantiation) section below.

### The Collection Class

[](#the-collection-class)

The `Collection` object will hold any value that a PHP array can hold, with the exception of `null`values.

A `Collection` can be instantiated empty or with an array of starting elements. In the latter scenario existing keys in the array are ignored.

```
