This is a discussion on Problem accessing variable variabla arrays ... within the PHP General forums, part of the PHP Programming Forums category; Hi all ! I've declared variables like this : $buttons[1]["name"] = "Test"; And now, for some ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all !
I've declared variables like this : $buttons[1]["name"] = "Test"; And now, for some reasons, I want to access to this value dynamically throught variable variable. Example : $var_name = "buttons"; $var_index1 = 1; $var_index2 = "name"; echo ${$var_name}[$var_index1][$varindex2]; Doesn't display anything ... instead of "Test". Can someone help me ? WFX |
|
|||
|
WFX wrote: > Hi all ! > > I've declared variables like this : > > $buttons[1]["name"] = "Test"; > > And now, for some reasons, I want to access to this value > dynamically throught variable variable. > > Example : > > $var_name = "buttons"; > $var_index1 = 1; > $var_index2 = "name"; > echo ${$var_name}[$var_index1][$varindex2]; > > Doesn't display anything ... instead of "Test". You're misssing an underscore in $varindex2 ... should be $var_index2. Ken |
|
|||
|
WFX wrote:
> Hi all ! > > I've declared variables like this : > > $buttons[1]["name"] = "Test"; > > And now, for some reasons, I want to access to this value > dynamically throught variable variable. > > Example : > > $var_name = "buttons"; > $var_index1 = 1; > $var_index2 = "name"; > echo ${$var_name}[$var_index1][$varindex2]; > > Doesn't display anything ... instead of "Test". > > Can someone help me ? I would try this: echo $$var_name[$var_index1][$var_index2]; |
|
|||
|
Yorn de Jong wrote: > I would try this: > > echo $$var_name[$var_index1][$var_index2]; There's an ambiguity with this solution. Does it mean "Take the value of $var_name[$var_index1] and turn it into a variable and then use $var_index2 as an index on the result" or does it mean "Take the value of $var_name and turn it into a variable and index it by [$var_index1][$var_index2]"? Using the curly brackets "{ }" tells PHP which interpretation is correct. Ken |