Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hedronium/keyarray
Using arrays as keys for associative arrays in php.
https://github.com/hedronium/keyarray
Last synced: 3 days ago
JSON representation
Using arrays as keys for associative arrays in php.
- Host: GitHub
- URL: https://github.com/hedronium/keyarray
- Owner: hedronium
- Created: 2016-12-23T19:39:00.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-23T19:42:42.000Z (almost 8 years ago)
- Last Synced: 2024-04-27T22:42:46.824Z (7 months ago)
- Language: PHP
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# KeyArray
Allowing you to use arrays as keys for associative arrays.
_Only supports flat arrays of scalar values._## Installation
```bash
composer require hedronium/key-array
```## Usage
Just Instantiate the class, or call the `KeyArray::array()` method to
instantiate it.```PHP
use Hedronium\KeyArray\KeyArray;$arr = new KeyArray;
// or
$arr = KeyArray::array();
```then proceed to use it like a normal array.
```PHP
$arr[[]] = 'The void in my heart.';
$arr[['a']] = 'AYY';
$arr[['b']] = 'BEE';
$arr[['a', 'b']] = 'AYY-BEE';
$arr[['a', 'b', 'c']] = 'AYY-BEE-CEE';
```iteration with `foreach` works too.
```PHP
foreach ($arr as $key => $val) {
echo str_pad(implode(' -> ', $key), 20, ' ', STR_PAD_LEFT);
echo ' = ';
echo $val;
echo PHP_EOL;
}////// OUTPUT: /////////////////////////
// = The void in my heart.
// a = AYY
// a -> b = AYY-BEE
// a -> b -> c = AYY-BEE-CEE
// b = BEE
```