Variable Variable Array
| From: | Ryan Jameson \(USA\) | Date: | Thu, 10 Mar 2005 18:56:16 +0000 |
| Subject: | Variable Variable Array | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-38857@lists.php.net to get a copy of this message | ||
Hi Folks,
I've been using "variable variables" for years with PHP.
$var = "myVarName";
$$var = "Some Val";
echo $myVarName; //outputs "Some Val"
...
Today I am trying to assign an Associative Array value to a "variable
variable". For some reason it doesn't take. Does anyone know why?
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.
The reason I want to do this is to speed up access to DATABASE query
results by use of the associative array. Since the results are keyed on
a specific column I'd like to load the very small recordset and then
access each row associatively on that column value. Currently I have to
requery the database every time, which is faster than loop/testing the
whole result set each time. I'd use a hashtable in Java but PHP ain't
Java. If ne1 has a better way I'm game.
Thanks for your help.
<>< Ryan