psx / record
数据哈希表实现
v3.0.8
2024-05-10 17:43 UTC
Requires
- php: >=8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^5.0
README
关于
本包提供了一种简单的HashMap实现,灵感来源于Java HashMap API。以下示例展示了如何使用record类
<?php use PSX\Record\Record; $record = new Record(); $record->put('foo', 'bar'); $record->putAll(['bar' => 'foo']); $record->containsKey('foo'); // checks whether the key exists $record->containsValue('bar'); // checks whether the value exists (strict type check) $record->get('foo'); $record->getOrDefault('foo', false); $record->foo; // property access $record['foo']; // array access $record->remove('bar'); $record->keySet(); // returns all keys as indexed array $record->size(); // returns the size of the map $record->values(); // returns all values as indexed array \json_encode($record); // results in {"foo": "bar"} $record = Record::from(['foo' => 'bar']); // create a record from an array