Re[2]: [PHP] How to convert an array to variables?

From: Date: Sun, 16 Mar 2003 01:08:46 +0000
Subject: Re[2]: [PHP] How to convert an array to variables?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139820@lists.php.net to get a copy of this message
Hi, Sunday, March 16, 2003, 8:20:49 AM, you wrote: CK> Tom, CK> This seems like what I need exactly, but I am having a bit of trouble CK> getting it to work. CK> Here is how I have worked around this, but I know there is a 'real' way CK> to do this. Any thoughts? I had to set the variables, or should I just CK> use the variables as ${dra_0} etc.? CK> // get the values for the default dra from array CK> while(list($key,$val) = each($r_p_dras)){ CK> $n = "dra_$key"; CK> echo $n; CK> $$n = $val['dra_id']; CK> } CK> $dra_a = "${dra_0}"; CK> $dra_b = "${dra_1}"; CK> $dra_c = "${dra_2}"; CK> $dra_d = "${dra_3}"; CK> $dra_e = "${dra_4}"; You could use a seperate counter like this: $x = 1; while(list($key,$val) = each($r_p_dras)){ $n = "dra_$x"; echo $n; $$n = $val['dra_id']; $x ++; } -- regards, Tom

« previous php.general (#139820) next »