mobileka / mosaic-array

A simple array manipulation class

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mosaic Array

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

About

A simple array manipulation class

License:MIT License


Languages

Language:PHP 100.0%