Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petrgrishin/array-access
PHP multi array access
https://github.com/petrgrishin/array-access
array array-map changing php yii yii2
Last synced: 4 months ago
JSON representation
PHP multi array access
- Host: GitHub
- URL: https://github.com/petrgrishin/array-access
- Owner: petrgrishin
- Created: 2014-04-29T18:10:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-29T08:58:16.000Z (almost 9 years ago)
- Last Synced: 2024-09-30T00:22:48.803Z (4 months ago)
- Topics: array, array-map, changing, php, yii, yii2
- Language: PHP
- Homepage: https://github.com/petrgrishin/array-access
- Size: 26.4 KB
- Stars: 23
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
array-access
============
[![Travis CI](https://travis-ci.org/petrgrishin/array-access.png "Travis CI")](https://travis-ci.org/petrgrishin/array-access)
[![Coverage Status](https://coveralls.io/repos/petrgrishin/array-access/badge.png?branch=master)](https://coveralls.io/r/petrgrishin/array-access?branch=master)
[![Latest Stable Version](https://poser.pugx.org/petrgrishin/array-access/v/stable.svg)](https://packagist.org/packages/petrgrishin/array-access)
[![Total Downloads](https://poser.pugx.org/petrgrishin/array-access/downloads.svg)](https://packagist.org/packages/petrgrishin/array-access)
[![License](https://poser.pugx.org/petrgrishin/array-access/license.svg)](https://packagist.org/packages/petrgrishin/array-access)PHP multi array access
Installation
------------
Add a dependency to your project's composer.json file if you use [Composer](http://getcomposer.org/) to manage the dependencies of your project:
```json
{
"require": {
"petrgrishin/array-access": "~2.0"
}
}
```Usage examples
--------------
#### Basic usage array-access objects
```php
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
```php
$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