solution10/collection

一个简单快速的集合类

v1.3.1 2014-11-29 20:24 UTC

This package is not auto-updated.

Last update: 2024-09-24 04:33:29 UTC


README

就像数组。但更好!

Build Status Coverage Status

Latest Stable Version Total Downloads Latest Unstable Version License

这能做什么?

集合在本质上实现了 Iterator、ArrayAccess 和 Countable。但它们的功能远不止于此。

只需通过传递键即可简单地拼接数组子部分

$collection = new Collection(array('Apple', 'Orange', 'Banana'));
$subset = $collection['0:1'];
// $subset is now: array('Apple', 'Orange')

$collection = new Collection(array('Apple', 'Orange', 'Banana'));
$subset = $collection['-2:2'];
// $subset contains ('Orange', 'Banana')

$collection = new Collection(array('Apple', 'Orange', 'Banana', 'Grapes'));
$subset = $collection[':LAST'];
// $subset is simply array('Grapes')

快速排序

$collection = new Collection(array(100, 50, 70, 10));
$collection->sort(Collection::SORT_ASC);
// $collection's order is now: 10, 50, 70, 100

$collection = new Collection(array(
    array(
        'name' => 'Sarah',
        'job' => 'Manager',
    ),
    array(
        'name' => 'Alex',
        'job' => 'Developer',
    ),
    array(
        'name' => 'Tracy',
        'job' => 'HR'
    ),
));
$collection->sortByMember('name', Collection::SORT_ASC);

要查看完整功能列表,请查看文档

安装

通过 composer 安装

"require": {
    "solution10/collection": "1.*"
}

要求

  • PHP >= 5.3

就是这样!

文档

请参阅Github Wiki存储库中的 docs 文件夹

要获取 API 文档;从项目检查中运行

$ make && open api/index.html

许可证

MIT

贡献

贡献者说明