solution10/collection

A simple and fast Collection class

v1.3.1 2014-11-29 20:24 UTC

This package is not auto-updated.

Last update: 2024-11-05 05:00:51 UTC


README

Like Arrays. Only better!

Build Status Coverage Status

Latest Stable Version Total Downloads Latest Unstable Version License

What does this do?

Collections, at their core, are implementations of Iterator, ArrayAccess and Countable. But they're also a lot more than that.

Splice subsections of arrays simply by passing keys:

$collection = new Collection(array('Apple', 'Orange', 'Banana'));
$subset = $collection['0:1'];
// $subset is now: array('Apple', 'Orange')

$collection = new Collection(array('Apple', 'Orange', 'Banana'));
$subset = $collection['-2:2'];
// $subset contains ('Orange', 'Banana')

$collection = new Collection(array('Apple', 'Orange', 'Banana', 'Grapes'));
$subset = $collection[':LAST'];
// $subset is simply array('Grapes')

Quickly and easily Sort

$collection = new Collection(array(100, 50, 70, 10));
$collection->sort(Collection::SORT_ASC);
// $collection's order is now: 10, 50, 70, 100

$collection = new Collection(array(
    array(
        'name' => 'Sarah',
        'job' => 'Manager',
    ),
    array(
        'name' => 'Alex',
        'job' => 'Developer',
    ),
    array(
        'name' => 'Tracy',
        'job' => 'HR'
    ),
));
$collection->sortByMember('name', Collection::SORT_ASC);

For full feature list, check out the docs.

Installation

Install via composer:

"require": {
    "solution10/collection": "1.*"
}

Requirements

  • PHP >= 5.3

That's it!

Documentation

See the Github Wiki or the docs/ folder in the repo.

To get api docs; from a checkout of the project run:

$ make && open api/index.html

License

MIT

Contributing

Contributors Notes