petrgrishin / array-access
PHP multi array access
Installs: 5 106
Dependents: 4
Suggesters: 0
Security: 0
Stars: 23
Watchers: 6
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
- petrgrishin/array-map: ~1.0
- petrgrishin/array-object: ~1.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-11-09 16:27:15 UTC
README
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