dev-master
9999999-devLightweight collection library
MIT
The Requires
- php >=5.6
The Development Requires
0.1.0
0.1.0.0Lightweight collection library
MIT
The Requires
- php >=5.6
The Development Requires
Lightweight collection library
Lightweight collection library -- by, Chris Kankiewicz, (*2)
composer require phlak/collection
First, import Collection:, (*3)
use PHLAK\Collection;
Then pass an array of items to the Collection
class or the static make
method:, (*4)
$collection = new Collection\Collection(['foo', 'bar', 'baz']); // or $collection = Collection\Collection::make(['foo', 'bar', 'baz']);
Iterate over each item in a collection and perform an action via a Closure:, (*5)
$collection->each(Closure $function);
Map each item of the collection to a new value via a Closure:, (*6)
$collection->map(Closure $function);
Filter the items in a collection by returning only the items where the Closure returns true:, (*7)
$collection->filter(Closure $function);
Filter the items in a collection by returning only the items where the Closure
returns false
(opposite of the filter
method):, (*8)
$collection->reject(Closure $function);
Reduce a collection down to a single item by iterating over the Closure until a single item remains:, (*9)
$collection->reduce(Closure $function, $initial);
Sum all the items in a collection and return the value:, (*10)
$collection->sum(Closure $function, $initial);
A list of changes can be found on the GitHub Releases page., (*11)
Please report bugs to the GitHub Issue Tracker., (*12)
This project is liscensed under the MIT License., (*13)
Lightweight collection library
MIT
Lightweight collection library
MIT