Do you mean something like this:

It creates a quick associative array from the resultset


From: "Ryan Jameson (USA)" <[EMAIL PROTECTED]>
To: <>
Subject: [PHP-DB] Variable Variable Array
Date: Thu, 10 Mar 2005 11:56:16 -0700

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?



$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

PHP Database Mailing List (
To unsubscribe, visit:

-- PHP Database Mailing List ( To unsubscribe, visit:

Reply via email to