Re: Variable Variable Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ryan Jameson (USA) wrote:
Hi Folks,

I've been using "variable variables" for years with PHP.

$var = "myVarName";
$$var = "Some Val";

echo $myVarName; //outputs "Some Val"
[snip]
Example:

$var['first']='bob';
$var['second']='frank';

$varName = "myVarName";
$$varName = $var;

echo $$varName['second']; //should output "frank" but doesn't. :-\
<-----------------------------
echo $var['second']; //should output "frank" works fine.

Try adding
$frank = 'woopsie!';
to the top of your script and running it.
-----
echo ${$VarName}['second'];
is what you want - you want to be very clear what order these things need to be analyzed in, especially when dealing with arrays and the likes.


Cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International Outreach x3257
The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux