rkr/recursive-array-accessor

Access recursive arrays through an easy interface

Installs: 114

Dependents: 2

Stars: 1

Watchers: 3

Language: PHP

3.0.1.3 2014-05-28 16:32 UTC

README

Build Status

Access n-dimensional arrays through an easy interface

Why, what?

Example:

// PHP5.4-style array syntax
$array = [];
$data = new ArrayPath\Map($array);
$data->set(['a', 'b', 'c'], 'test'); // equals $data['a']['b']['c'] = 'test';
print_r($data->asArray());

echo $data->getString(['a', 'b', 'd'], 'fallback'); // -> "fallback"
print_r($data->getArray(['a', 'b', 'd'], ['fallback'])); // -> ["fallback"]

You can also use strings as a path:

$array = [];
$data = new StringPath\Map($array);
$data->set('a.b.c', 'test'); // equals $data['a']['b']['c'] = 'test';
print_r($data->asArray());

echo $data->getString('a.b.d', 'fallback'); // -> "fallback"
print_r($data->getArray('a.b.d', ['fallback'])); // -> ["fallback"]

Composer:

https://packagist.org/packages/rkr/recursive-array-accessor