array-map

The object oriented approach to working with arrays
3 followers

The object oriented approach to working with arrays

https://github.com/petrgrishin/array-map

Installation

Add a dependency to your project's composer.json:

{
    "require": {
        "petrgrishin/array-map": "~1.0"
    }
}

Usage examples

Map

Using keys

$array = ArrayMap::create($array)
    ->map(function ($value, $key) {
        return array($key => $value);
    })
    ->getArray();

Simple

$array = ArrayMap::create($array)
    ->map(function ($value) {
        return $value;
    })
    ->getArray();

Merge

Recursive merge

$array = ArrayMap::create($array)
    ->mergeWith(array(
        1 => 1,
        2 => 2,
        3 => array(
            1 => 1,
            2 => 2,
        ),
    ))
    ->getArray();

One level merge

$array = ArrayMap::create($array)
    ->mergeWith(array(
        1 => 1,
        2 => 2,
    ), false)
    ->getArray();

Filtering

$array = ArrayMap::create($array)
    ->filter(function ($value, $key) {
        return $value > 10 && $key > 2;
    })
    ->getArray();

Be the first person to leave a comment

Please to leave your comment.

Create extension