blar / common
此包已被废弃且不再维护。未建议替代包。
PHP通用
dev-master
2015-11-28 03:32 UTC
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
通用
集合
$collection = new Collection(array(
'foo' => 23,
'bar' => 42
));
集合
$collection->set('foobar', 1337);
有
$boolean = $collection->has('foo');
获取
$foo = $collection->get('foo');
搜索
$index = $collection->search(42);
连接
$string = $collection->join(',');
映射
$iterator = $collection->map(function($value, $index) {
return $value * 2;
});
过滤
$iterator = $collection->filter(function($value, $index) {
return $value % 2 == 0;
});
减少
$query = $collection->reduce(function($result, $value, $index) {
if($result != '?') {
$result .= '&';
}
$result .= $index.'='.$value;
return $result;
}, '?');