Skip to content

hedronium/KeyArray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeyArray

Allowing you to use arrays as keys for associative arrays. Only supports flat arrays of scalar values.

Installation

composer require hedronium/key-array

Usage

Just Instantiate the class, or call the KeyArray::array() method to instantiate it.

use Hedronium\KeyArray\KeyArray;

$arr = new KeyArray;

// or
$arr = KeyArray::array();

then proceed to use it like a normal array.

$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.

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

About

Using arrays as keys for associative arrays in php.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages