1. Go to this page and download the library: Download kozz/collection library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kozz / collection example snippets
use Kozz\Components\Collection;
$collection = new Collection();
$traversable = new \ArrayIterator(range(1,1000));
$collection = Collection::from($traversable);
$mongo = new \MongoClient();
$cursor = $mongo->selectDB('testDB')->selectCollection('testCollection')->find();
$collection = new Collection($cursor);
use Kozz\Components\Collection;
$mongo = new \MongoClient();
$cursor = $mongo->selectDB('testDB')->selectCollection('testCollection')->find();
//[0=>['_id'=>MongoId(...), 'value'=>123], ...]
$collection = new Collection($cursor);
$collection->addModifier(function(&$item){
$item['id'] = (string)$item['_id'];
});
$collection->addModifier(function(&$item){
unset($item['_id']);
});
foreach($collection->getFilterIterator() as $item)
{
// $item = ['id'=>'4af9f23d8ead0e1d32000000', 'value'=>123]
}