Get Array value by string of keys

Posted by Esben Petersen on Stack Overflow See other posts from Stack Overflow or by Esben Petersen
Published on 2011-02-26T15:20:26Z Indexed on 2011/02/26 15:25 UTC
Read the original article Hit count: 187

Filed under:
|
|

Hello, i'm building a template engine for my next project, which is going great. It replaces {tag} with a corresponding value. But, i want {tag[0][key]} to be replaced as well. All i need to know is how to get the value, if i have the string representation of the array and key, like this:

$arr = array(
    0=>array(
        'key'=>'value'
    ),
    1=>array(
        'key'=>'value2'
    )
);

$tag = 'arr[0][key]';

echo($$tag);

This is a very simple version of the problem, i hope you understand it. Or else i would be happy to anwser any questions about it :)

Thanks for any help in advantage

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays