PHPackages                             kohkimakimoto/earray - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kohkimakimoto/earray

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kohkimakimoto/earray
====================

EArray is a small PHP class to provide convenient ways to access a PHP array.

v2.3.0(9y ago)176.1k1Apache License 2.0PHPPHP &gt;=5.3.0

Since Oct 23Pushed 9y ago2 watchersCompare

[ Source](https://github.com/kohkimakimoto/EArray)[ Packagist](https://packagist.org/packages/kohkimakimoto/earray)[ Docs](https://github.com/kohkimakimoto/EArray)[ RSS](/packages/kohkimakimoto-earray/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

EArray
======

[](#earray)

[![Build Status](https://camo.githubusercontent.com/630e629acdcadb7424b91ed485782352e42fda7c8bb974d851da7ad2898b58d4/68747470733a2f2f7472617669732d63692e6f72672f6b6f686b696d616b696d6f746f2f4541727261792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/kohkimakimoto/EArray)[![Coverage Status](https://camo.githubusercontent.com/c8c4f004c34151313bd7533b669cf7c64c34d7277eb7cd965791beb9b46c0c07/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b6f686b696d616b696d6f746f2f4541727261792f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/kohkimakimoto/EArray?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/5b2c542d552f8b712d4cd0a4c6eb082c27d46095f59795443952ed86dc012ff6/68747470733a2f2f706f7365722e707567782e6f72672f6b6f686b696d616b696d6f746f2f6561727261792f762f737461626c652e706e67)](https://packagist.org/packages/kohkimakimoto/earray)

EArray is a small PHP class to provide convenient ways to access a PHP array.

- Convenient accessing to a nested array.
- You can use a default value when you try to get a value of array.
- You can use this object as a normal array (Implementing `ArrayAccess`, `Iterator` and `Countable` interfase).
- It has some convenient methods for array: `each`, `filter`, `sort`.
- You can register custom methods to array.

It aims to remove code that checks array key existence. Especially for a nested array. Do you hate the code like the below?

```
$val = null;
$arr2 = isset($arr["key"]) ? $arr["key"] : null;
if (is_array($arr2)) {
    $val = isset($arr2["key2"]) ? $arr2["key2"] : null;
}

echo $val;
```

You can write same things using EArray object.

```
echo $earray->get("key/key2", null);
```

Requirement
-----------

[](#requirement)

PHP5.3 or later.

Installation
------------

[](#installation)

You can use composer installation. Make `composer.json` file like the following.

```
{
      "require": {
          "kohkimakimoto/earray": "2.2.*"
      }
}
```

And run composer install command.

```
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

```

Usage
-----

[](#usage)

- [Basic operations](#basic-operations)
- [Convenient methods](#convenient-methods)
    - [each](#each)
    - [filter](#filter)
    - [sort](#sort)
- [Registering a custom method](#registering-a-custom-method)

### Basic operations

[](#basic-operations)

You can use `get`, `set`, `exists` and `delete` methods.

```
