array-map The object oriented approach to working with arrays

  1. Installation
  2. Usage examples

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();
1 0
3 followers
132 downloads
Yii Version: all
License: MIT
Category: Others
Developed by: Petr.Grishin
Created on: Jun 1, 2014
Last updated: 10 years ago

Downloads

show all

Related Extensions