Download the PHP package justinskolnick/key-value without Composer
On this page you can find all versions of the php package justinskolnick/key-value. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download justinskolnick/key-value
More information about justinskolnick/key-value
Files in justinskolnick/key-value
Package key-value
Short Description KeyValue provides an interface for managing associative arrays as a collection of key-value pairs.
License MIT
Informations about the package key-value
KeyValue
KeyValue provides an interface for managing associative arrays as a collection of key-value pairs.
It handles common but often complex operations like confirming membership and overwriting nested values in multi-dimensional arrays. Like so:
KeyValue is one of a number of tools I'm hoping to extract from older, larger projects.
Installation
To install this library with Composer, type:
Local installation is possible using the repositories block of your composer.json. For instance:
Usage
KeyValue collections are associative arrays, with mixed-type values saved at keys. Keys must be strings:
If a KeyValue item's value is an array, the key can include a slash to access a value at the second level of the array:
To get started, initiate a new KeyValue collection:
A collection can also be initiated with values:
Set a value or many values:
Confirm that any values have been set:
Confirm that a key exists, or that a value has been set at a given key:
Get a value for a given key:
Get all values for all keys, or only the keys, or only the values:
Remove an item (and confirm the deletion):
Reset the collection to null (and confirm the reset):
Reset the collection to null (and confirm the reset):
Confirm the collection is empty:
Confirm the collection is a non-null empty array:
Confirm the collection is null (such as on init or after a reset):
Style
Readers will note that the code, tests, and examples in this README don't meet the requirements of PSR-2 or PSR-12. Instead, they follow conventions I adopted a long time ago to help me scan PHP code. While this personal style is expected to be followed in PRs on this repository, it's not a requirement of use.
License
Copyright (c) 2025 Justin Skolnick. MIT License.