Skip to content

solution10/collection

Repository files navigation

Solution10\Collection

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

About

Like arrays, only better! Small, lightweight PHP 5.3 Collection class with smart slicing and fancy sorting.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages