Bluehost.com Web Hosting $6.95

Problem accessing variable variabla arrays ...

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-09-2005
WFX
 
Posts: n/a
Default Problem accessing variable variabla arrays ...

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
Reply With Quote
  #2 (permalink)  
Old 02-09-2005
Ken Robinson
 
Posts: n/a
Default Re: Problem accessing variable variabla arrays ...


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

Reply With Quote
  #3 (permalink)  
Old 02-10-2005
Yorn de Jong
 
Posts: n/a
Default Re: Problem accessing variable variabla arrays ...

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];
Reply With Quote
  #4 (permalink)  
Old 02-10-2005
Ken Robinson
 
Posts: n/a
Default Re: Problem accessing variable variabla arrays ...


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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:10 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0