mobileka/mosaic-array

A simple array manipulation class

1.0.0 2015-02-16 07:11 UTC

This package is not auto-updated.

Last update: 2024-12-21 18:33:19 UTC


README

Build Status Coverage Status Code Climate

A simple array manipulation class.

Requirements:

PHP >= 5.4.*

Some examples:

A very common case when you need to do something like this:

if (isset($arr['key']) {
	$result = $arr['key'];
} else {
	$result = 'default';
}

// another way to write the same thing
$result = isset($arr['key']) ? $arr['key'] : 'default';

With MosaicArray you can do the same thing more elegantly:

$result = MosaicArray::make($arr)->getItem('key', 'default');
//or
$ma = new MosaicArray($arr);
$result = $ma->getItem('key', 'default');

MosaicArray implements ArrayAccess, IteratorAggregate, Countable and Serializable interfaces, so you can access an instance of this class as an array, iterate over it, count elements, serialize and unserialize it:

$numbers = new MosaicArray([1, 2, 3]);

echo $numbers[0]; //1

foreach ($numbers as $number) {
	// do something
}

echo count($numbers); // 3

serialize($numbers);
unserialize($numbers);

License

MosaicArray is open-source and licensed under the MIT License