2017 © Pedro Peláez
 

library array-map

The object oriented approach to working with arrays on PHP

image

petrgrishin/array-map

The object oriented approach to working with arrays on PHP

  • Friday, June 22, 2018
  • by petrgrishin
  • Repository
  • 3 Watchers
  • 9 Stars
  • 1,663 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 4 % Grown

The README.md

array-map

Travis CI Coverage Status, (*1)

The object oriented approach to working with arrays, (*2)

Installation

Add a dependency to your project's composer.json:, (*3)

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

Usage examples

Map

Using keys, (*4)

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

Simple, (*5)

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

Merge

Recursive merge, (*6)

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

One level merge, (*7)

$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();

User sort

Sort by value, (*8)

$array = ArrayMap::create($array)
    ->userSortByValue(function ($first, $second) {
        return $first < $second ? -1 : 1;
    })
    ->getArray();

Sort by key, (*9)

$array = ArrayMap::create($array)
    ->userSortByKey(function ($first, $second) {
        return $first < $second ? -1 : 1;
    })
    ->getArray();

Example of use

ArrayAccess class, multi array access — https://github.com/petrgrishin/array-access, (*10)

The Versions

22/06 2018

dev-master

9999999-dev

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petr Grishin

22/06 2018

1.4.0

1.4.0.0

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petr Grishin

08/04 2015

1.3.1

1.3.1.0

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petr Grishin

15/07 2014

1.3.0

1.3.0.0

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petr Grishin

25/06 2014

1.2.0

1.2.0.0

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Petr Grishin

20/06 2014

1.1.0

1.1.0.0

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Petr Grishin

01/06 2014

1.0.0

1.0.0.0

The object oriented approach to working with arrays on PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Petr Grishin