punarinta/apath

A way to access data for multidimensional PHP arrays and objects.

v1.0 2017-02-09 13:47 UTC

This package is not auto-updated.

Last update: 2025-03-29 23:15:57 UTC


README

A way to access data in objects and multidimensional arrays.

Usage

use APath\APath;

$sample =
[
    'foo' =>
    [
        'bar' =>
        [
            'x1' => 'hello, world',
            'x2',
            'x3' => 'bye-bye, world',
        ],
    ],
    'some' =>
    [
        'data',
        'x1337' => 'LEET',
    ],
    [1, 4, 'xxx' => 'yyy', 88],
];

// get the whole structure
print_r(APath::get($sample));

// get by keys
print_r(APath::get($sample, 'foo.bar'));

// or by numeric offset
print_r(APath::get($sample, '0.2'));

// or even combine them
print_r(APath::get($sample, 'some.0'));

// trying to get a non-existent part will simply result a null 
print_r(APath::get($sample, 'some.unreal.path'));