naoyuki42/php-keyed-collection
最新稳定版本:0.1.0
Composer 安装命令:
composer require naoyuki42/php-keyed-collection
包简介
A PHP library that provides a keyed collection class with type safety and immutability.
README 文档
README
Overview
php-keyed-collection is a PHP library that provides a type-safe and immutable keyed collection class.
It supports keys and values of any type, including arrays, objects, and null.
Features
- Support for keys of any type (string, int, float, bool, array, object, null, etc.)
- Methods for getting, setting, deleting, checking existence, clearing, and iterating values
- Implements
CountableandIteratorinterfaces forforeachandcount()support - Readonly
sizeproperty for getting the number of elements
Installation
composer require naoyuki42/php-keyed-collection
Usage
use Naoyuki42\KeyedCollection\Map; $map = new Map(); // Setting values $map->set('key1', 'value1'); $map->set(123, 'value2'); $map->set([1,2], 'value3'); $obj = new stdClass(); $map->set($obj, 'value4'); // Getting values echo $map->get('key1'); // value1 echo $map->get(123); // value2 // Checking existence var_dump($map->has([1,2])); // true // Deleting values $map->delete('key1'); // Getting size echo $map->size; // 3 // Clearing all entries $map->clear(); // Iteration foreach ($map as $key => $value) { var_dump($key, $value); }
License
MIT
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-11