Re: How to convert an array to variables?

From: Date: Sat, 15 Mar 2003 19:08:37 +0000
Subject: Re: How to convert an array to variables?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-139803@lists.php.net to get a copy of this message
Hi, Sunday, March 16, 2003, 4:52:10 AM, you wrote: CK> Hi all, CK> I have an array that gives me this when I do: CK> print_r($my_array); CK> Array CK> ( CK> [0] => Array CK> ( CK> [dra_id] => 5 CK> ) CK> [1] => Array CK> ( CK> [dra_id] => 8 CK> ) CK> [2] => Array CK> ( CK> [dra_id] => 9 CK> ) CK> ) CK> using a foreach() I want to create a variable with a unique incremental CK> name for each of the values. CK> for example: CK> $dra_1 = 5; CK> $dra_2 = 8; CK> $dra_3 = 9; CK> How would I do this? A variable that has a variable name based on a CK> counter in the loop? Not sure the syntax for that. CK> Thanks CK> Charles something like this... while(list($key,$val) = each($my_array)){ $n = 'dra_'.$key+1; $$n = $val['dra_id']; } -- regards, Tom

« previous php.general (#139803) next »