rkr/recursive-array-accessor

Access recursive arrays through an easy interface

4.0 2022-08-08 11:07 UTC

This package is auto-updated.

Last update: 2024-11-08 16:21:33 UTC


README

Build Status

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"]

Composer:

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