ialopezg / collections
PHP 集合管理基础库
v0.0.2
2020-09-17 06:56 UTC
Requires
- php: ^5.6 || ^7.0
This package is auto-updated.
Last update: 2024-09-17 16:31:56 UTC
README
基于PHP的集合管理器
安装
composer require ialopezg/collections
要求
- PHP 5.6+
功能
- 设置项
- 更新项
- 移除项
- 查找项
- 单次查找时通过键名
- 嵌套查找时通过点表示法
- 数据缓存以快速访问
- 通过在类中调用其名称访问第一级对象,例如:
echo $collection->itemName;。受保护的属性不能调用。 - 类合并派生自
CollectionInterface。 - 像关联数组一样访问其项。
使用方法
use ialopezg\Libraries\Collection; // class derived from Collection class class ItemCollection extends Collection { } $collection = new ItemCollection([]); // get the value, if not found return default value echo $collection->get('item_name', 'initial value'); // changing item_name's value $collection->set('item_name', 'item value'); // print current value if ($collection->has('item_name')) { echo $collection->get('item_name'); } // remove item_name property $collection->remove('item_name'); echo $collection->count();
请检查 examples 目录以获取更多使用详细信息,或运行
### from linux bash
./server.sh
或
### from windows bash
server.bat
许可证
本项目采用MIT许可证。更多信息请参阅 LICENSE。