A Collections Abstraction library for PHP
The Collection library is one of the most useful things that many modern languages has, but for some reason PHP doesn't has a built in collection layer.
The package requires PHP 5.4+ and follows the FIG standards PSR-1, PSR-2 and PSR-4 to ensure a high level of interoperability between shared PHP code and is fully unit-tested.
Instantiate a new Collection
$collection = new Cartalyst\Collections\Collection([ 'item1' => 'Item 1', 'item2' => 'Item 2', ]);
Get how many items are inside a Collection
echo $collection->count(); // > 2
Retrieve an item inside of the Collection
echo $collection->item1; // Item 1
The best and easiest way to install the Collections package is with Composer.
composer.json file and add the following to the
Note: Make sure that after the required changes your
composer.jsonfile is valid by running
Install the dependencies
Run Composer to install or update the new requirement.
php composer install
php composer update
Now you are able to require the
vendor/autoload.php file to autoload the package.
In this section we'll show how to use the Collection class.