假设我有一个类似的数组:
Array
(
[0] => Array
(
[Data] => Array
(
[id] => 1
[title] => Manager
[name] => John Smith
)
)
[1] => Array
(
[Data] => Array
(
[id] => 1
[title] => Clerk
[name] =>
(
[first] => Jane
[last] => Smith
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
我希望能够构建一个函数,我可以传递一个字符串,作为数组索引路径,并返回适当的数组值而不使用eval().那可能吗?
function($indexPath, $arrayToAccess)
{
// $indexPath would be something like [0]['Data']['name'] which would return
// "Manager" or it could be [1]['Data']['name']['first'] which would return
// "Jane" but the …Run Code Online (Sandbox Code Playgroud)