Clone or download
petrgrishin Update .travis.yml
Temporarily remove the testing php7 by travis-ci error
Latest commit 0e0ed49 Mar 29, 2016
Permalink
Failed to load latest commit information.
src Рефакторинг класса исключений Jul 15, 2014
tests
.gitignore
.travis.yml
README.md
composer.json
phpunit.xml
phpunit.xml.dist

README.md

array-access

Travis CI Coverage Status Latest Stable Version Total Downloads License

PHP multi array access

Installation

Add a dependency to your project's composer.json file if you use Composer to manage the dependencies of your project:

{
    "require": {
        "petrgrishin/array-access": "~2.0"
    }
}

Usage examples

Basic usage array-access objects

use \PetrGrishin\ArrayAccess\ArrayAccess;

$arrayParams = array(
    'a' => array(
        'b' => 10,
    )
);
$params = ArrayAccess::create($arrayParams);
$value = $params->getValue('a.b');
$params
    ->setValue('a.b', 20)
    ->setValue('a.c', 30);
$params->remove('a.b');
$resultArrayParams = $params->getArray();
// array(
//     'a' => array(
//         'c' => 30,
//     )
// )

Use ArrayMap

$arrayAccess = ArrayAccess::create($array);
$arrayAccess->getMap()
    ->filter($callback)
    ->map($callback)
    ->userSortByValue($callback)
    ->userSortByKey($callback)
    ->mergeWith($array)
    ->replaceWith($array);
$resultArrayParams = $arrayAccess->getArray();

Example of usage ArrayMap class — https://github.com/petrgrishin/array-map

Example of usage in Yii2 behavior

https://github.com/petrgrishin/yii2-array-field