dynamically accessing arrays at variable indexes
| From: | Dale Robinson | Date: | Fri, 09 Mar 2001 19:52:28 +0000 |
| Subject: | dynamically accessing arrays at variable indexes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-43198@lists.php.net to get a copy of this message | ||
Hi,
I need to access array values at varying dimensions.
What I want to do is something like this:
$full_index = ["op"]["view"];
print ${"HTTP_GET_VARS" . $full_index};
but that doesnt work :(
A messy solution would be:
function return_array_value($index1, $index2)
{
if ($index2) {
return $HTTP_GET_VARS[$index1][$index2];
} else {
return $HTTP_GET_VARS[$index1];
}
}
but this would mean I would have to continue adding 'if' clauses if I wanted
to access values more than one dimension deep.
Is there a neat way of getting at array values dynamically?
D. Robinson