blar/common

This package is abandoned and no longer maintained. No replacement package was suggested.

Common for PHP

dev-master 2015-11-28 03:32 UTC

This package is auto-updated.

Last update: 2018-09-29 14:21:06 UTC


README

License Latest Stable Version Build Status Coverage Status Dependency Status

Common

Collection

$collection = new Collection(array(
    'foo' => 23,
    'bar' => 42
));

Set

$collection->set('foobar', 1337);

Has

$boolean = $collection->has('foo');

Get

$foo = $collection->get('foo');

search

$index = $collection->search(42);

Join

$string = $collection->join(',');

Map

$iterator = $collection->map(function($value, $index) {
    return $value * 2;
});

Filter

$iterator = $collection->filter(function($value, $index) {
    return $value % 2 == 0;
});

Reduce

$query = $collection->reduce(function($result, $value, $index) {
    if($result != '?') {
        $result .= '&';
    }
    $result .= $index.'='.$value;
    return $result;
}, '?');