PHPackages                             kozz/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. [File &amp; Storage](/categories/file-storage)
4. /
5. kozz/collection

ActiveLibrary[File &amp; Storage](/categories/file-storage)

kozz/collection
===============

Powerful Data Storage based on SplDoublyLinkedList

1.3.2(11y ago)420.2k↓50%21MITPHPPHP &gt;=5.4.0

Since Jul 30Pushed 11y ago1 watchersCompare

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

READMEChangelog (8)Dependencies (2)Versions (10)Used By (1)

PHP Collection
==============

[](#php-collection)

[![Build Status](https://camo.githubusercontent.com/32da63d20f9e6e34beda60ebecbabc36d7612b079297b0b143448e00fa6edb7e/68747470733a2f2f7472617669732d63692e6f72672f7572616b6f7a7a2f7068702d636f6c6c656374696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/urakozz/php-collection)[![Coverage Status](https://camo.githubusercontent.com/2649a731f615c43fa991e22a5e42f2180986c34a99fc60603fe1d556377acd2a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f7572616b6f7a7a2f7068702d636f6c6c656374696f6e2f62616467652e706e67)](https://coveralls.io/r/urakozz/php-collection)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0f213fcb30ea53ba4a3e9b89e0e8e3b351f1f10f1c2472c412219faadc301069/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7572616b6f7a7a2f7068702d636f6c6c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/urakozz/php-collection/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/587124dd5e0b0ca157afdd388f0a262ea93450937414f943bf5811bc7a21793f/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7a7a2f636f6c6c656374696f6e2f762f737461626c652e737667)](https://packagist.org/packages/kozz/collection)[![Latest Unstable Version](https://camo.githubusercontent.com/f9d77cf424bd08cd34ec717a892889731e947af30a359f14477f9a2edf030027/68747470733a2f2f706f7365722e707567782e6f72672f6b6f7a7a2f636f6c6c656374696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/kozz/collection)[![License](https://camo.githubusercontent.com/6632de5b4224a7adb3e63bba6e3d4735de3467584e6988c5fe36e4766a57cefe/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b6f7a7a2f636f6c6c656374696f6e2e737667)](https://packagist.org/packages/kozz/collection)

Data Structure based on SplDoublyLinkedList.

Numerical keys, consequentially increasing, no gaps possible. Quick sequential iterating.

Advantages:

- Using Lamda Modifiers (see `addModifier` method)
- Regular array compatiable (`ArrayAccess` interface implemented)

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

[](#installation)

Add the package to your `composer.json` and run `composer update`.

```
{
    "require": {
        "kozz/collection": "*"
    }
}

```

Basic Usage
-----------

[](#basic-usage)

**Initializing**

```
    use Kozz\Components\Collection;
    $collection = new Collection();
```

**Initializing from any Traversable or Iterator**

1. You can initiate collection as SplDoublyLinkedList-based structure with `Collection::from($traversable)`

    ```
        $traversable = new \ArrayIterator(range(1,1000));
        $collection = Collection::from($traversable);
    ```
2. You also able to use your `Iterator` as `Collection`'s data container with `new Collection($iterator)`. Your iterator will converts to SplDoublyLinkedList once you try use any method from `ArrayAccess` or `Countable` interfaces implemented in `Collection`. This is good solution if your iterator is cursor in big DB Data Set and you need just add some modifiers with `addModifier`

    ```
        $mongo = new \MongoClient();
        $cursor = $mongo->selectDB('testDB')->selectCollection('testCollection')->find();
        $collection = new Collection($cursor);
    ```

Modifiers
---------

[](#modifiers)

Sometimes you should modify your data in collection

#### With Collection

[](#with-collection)

Modifiers are quite helpful to process DB Data Sets. And with this `Collection` you are able simply add modifier in just one line:

```
    use Kozz\Components\Collection;

    $mongo = new \MongoClient();
    $cursor = $mongo->selectDB('testDB')->selectCollection('testCollection')->find();
    //[0=>['_id'=>MongoId(...), 'value'=>123], ...]

    $collection = new Collection($cursor);
    $collection->addModifier(function(&$item){
        $item['id'] = (string)$item['_id'];
    });
    $collection->addModifier(function(&$item){
        unset($item['_id']);
    });
```

So now Modifiers are stored in `Collection` and you have two ways to apply it:

1. use `getFilterIterator()` method to get an Iterator with all applied modifiers:

    ```
        foreach($collection->getFilterIterator() as $item)
        {
            // $item = ['id'=>'4af9f23d8ead0e1d32000000', 'value'=>123]
        }
    ```
2. Call `->toArray()` that calls `getFilterIterator()` :

    ```
        $array = $collection->toArray();
        //$item = [ 0=> ['id'=>'4af9f23d8ead0e1d32000000', 'value'=>123], ...]
        foreach($array as $item)
        {
            //do stuff
        }
    ```

#### Without Collection

[](#without-collection)

You actually can modify your data with plain SPL:

```
    $mongo = new \MongoClient();
    $cursor = $mongo->selectDB('testDB')->selectCollection('testCollection')->find();

    $it = new CallbackFilterIterator($cursor, function(&$item){
        $item['id'] = (string)$item['_id'];
        return true;
    });
    $it = new CallbackFilterIterator($it, function(&$item){
        unset($item['_id']);
        return true;
    });

    foreach($array as $item)
    {
        // $item = ['id'=>'4af9f23d8ead0e1d32000000', 'value'=>123]
    }
```

ArrayAccess
-----------

[](#arrayaccess)

**Adding element**

```
    $element = 'string';
    $collection->push($element);
    //or
    $collection[] = $element;
```

**Replacing element**

```
    $element2 = new stdClass();
    $collection->set(0, $element2);
    //or
    $collection[0] = $element2;
    // This throws Exception (offset 100 not exists)
    $collection->set(100, $element2);
```

**Check offset**

```
    $collection->exists(0);
    //or
    isset($collection[0]);
```

**Retrieve element**

```
    $element = $collection->get(0);
    //or
    $element = $collection[0];
```

**Remove element**

```
    $element = $collection->remove(0);
    //or
    $element = unset($collection[0]);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~1 days

Total

9

Last Release

4301d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f78e5a1e5128b31ba7dfedcc9a3ccfbc4852f5df1b79a54867aa377169968a1?d=identicon)[urakozz](/maintainers/urakozz)

---

Top Contributors

[![urakozz](https://avatars.githubusercontent.com/u/5797393?v=4)](https://github.com/urakozz "urakozz (30 commits)")

---

Tags

phpiteratorstoragecollectionsplcursorLinkedList

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[rsd/seafile-php-sdk

This is a PHP package for accessing Seafile Web API

3589.1k](/packages/rsd-seafile-php-sdk)

PHPackages © 2026

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