blar / common
Common for PHP
Installs: 326
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/blar/common
Requires
- php: >=5.5.0
Requires (Dev)
- blar/php-coveralls: dev-master
This package is auto-updated.
Last update: 2018-09-29 14:21:06 UTC
README
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;
}, '?');