punarinta / apath
访问多维PHP数组和对象数据的途径。
v1.0
2017-02-09 13:47 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-14 19:42:24 UTC
README
访问对象和多维数组中的数据。
用法
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'));