rkr / recursive-array-accessor
Access recursive arrays through an easy interface
4.0
2022-08-08 11:07 UTC
Requires (Dev)
- php: >= 5.6
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9
README
Access to n-dimensional arrays via a simple 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"]