[pmwiki-devel] php multi-dimensional array construction problem

Daniel Roesler diafygi at gmail.com
Thu Feb 5 11:15:28 CST 2009


On Thu, Feb 5, 2009 at 9:36 AM, Hans <design5 at softflow.co.uk> wrote:
>
> I am really talking about an array as tree, and a way to direct you
> to a particular leaf, and use the initial string as the node map.
> So it is a multi-branch mapping problem.
>

Ah, I understand now. Maybe you could construct the variable call as a
string, then eval it. I'm assuming you aren't searching, so you don't
need to search all the leaves of the tree, just query a particular
leaf.

For example:
$tree = array(...); //Your tree array that you will be querying.
$string = 'k1:k2:k3:...:kn';
$tree_query = '$val = $tree[\'';
$tree_query .= str_replace(':', '\'][\'', $string).'\'];';
eval($tree_query);

Recursion is complicated, but this way is pretty unsafe. If users
input $string, you are open to them inserting something that can be
run in php.

Avast!
Daniel Roesler
diafygi at gmail.com



More information about the pmwiki-devel mailing list