small/collection

Provide PHP collection classes, with a selector to make complex queries on collections.

2.2.0 2024-03-17 16:44 UTC

This package is auto-updated.

Last update: 2024-04-17 17:00:18 UTC


README

small-collection.svg

coverage-badge.png             tests-badge.png



Provide PHP collection classes, with a selector to make complex queries on collections.

Beware : there is a break in compatibilty with version 1.x

Be careful to set your all packages composer.json to avoid breaking your code

Collection

Collections are classes that you can use as array.

Use it as array

The Small\Collection\Collection class is the base collection class.

You can create an empty collection :

$collection = new \Small\Collection\Collection\Collection();

Or initialize it with an array :

$collection = new \Small\Collection\Collection\Collection([1, 2, 3, 4]);

The collection has the behaviour of an array but is also an object :

$collection = new \Small\Collection\Collection\Collection([1, 2, 3, 4]);
foreach ($collection as $value) {
    echo $value;
}

Use it as an object

You can set a value for a specific key :

$collection = new \Small\Collection\Collection\Collection();
$key = 101;
$value = 'test';
$collection->set($key, $value);

And use it :

echo $collection[$key];

Collection classes

Selector

You can select arrays like it was a database table.

See Small\Collection\Selector\CollectionSelector.

small-collection is a part of small-project
Copyright (c) 2023,2024 Sébastien Kus
under GNU GPL V3 Licence