> -----Original Message----- > From: Charles Kline [mailto:[EMAIL PROTECTED] > Sent: 15 March 2003 18:52 > > I have an array that gives me this when I do: > > print_r($my_array); > > Array > ( > [0] => Array > ( > [dra_id] => 5 > ) > > [1] => Array > ( > [dra_id] => 8 > ) > > [2] => Array > ( > [dra_id] => 9 > ) > > ) > > using a foreach() I want to create a variable with a unique > incremental > name for each of the values. > > for example: > > $dra_1 = 5; > $dra_2 = 8; > $dra_3 = 9; > > How would I do this? A variable that has a variable name based on a > counter in the loop? Not sure the syntax for that.
Well, first question is: why do you want the individual variables? -- wouldn't a more compact array work better? (Genuine question -- you may have a legitimate reason for doing it the way you've asked!) You could create a 1-dimensional array keyed off the dra_ids like this: foreach ($my array as $key=>$sub): $dra_ids[$key] = $sub['dra_id']; endforeach; This makes $dra_ids be an array like: Array ( [0] => int(5) [1] => int(8) [2] => int(9) ) so that instead of using $dra_1 etc, you could use $dra_ids[0] etc. (As a final touch, if you now no longer need the original array, you could do: unset ($my_array); ) Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php