Re: Extracting Array value as variable

From: Date: Sat, 05 May 2001 03:00:44 +0000
Subject: Re: Extracting Array value as variable
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-51495@lists.php.net to get a copy of this message
Philip, Thank you, thank you, thank you!!! I have been working on this for a LONG TIME!! The answer was the {} brackets. I really appreciate it. John McConnell > From: philip@cornado.com (Philip Olson) > Newsgroups: php.general > Date: 4 May 2001 18:39:27 -0700 > Subject: Re: [PHP] Extracting Array value as variable > > > An example : > > <?php > > $array = array('a' => 'apple', > 'b' => 'banana', > 'c' => 'cranberry'); > > > print $array['a']; // apple > print $array['b']; // banana > > extract($array); > > print $a; // apple > print $b; // banana > > $var = 'array'; > > print ${$var}['a']; // apple > print ${$var}['b']; // banana > > ?> > > regards, > philip > > > On Fri, 4 May 2001, John McConnell wrote: > >> I have an array $veg that is set so $veg[0]="broccoi" & >> $veg[1]="tomatotes". >> I have also assigned values to the variables $broccoli=1 and $tomatoes=2. >> I want to print the values for those variables ($broccoli and $tomatoes) by >> only using the $veg array. >> >> So, if it worked it would be $$veg[0] would be 1, and $$veg[1] would be 2. >> >> Is there anyway to do this? >> >> Many thanks! >> >> John McConnell >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >> For additional commands, e-mail: php-general-help@lists.php.net >> To contact the list administrators, e-mail: php-list-admin@lists.php.net >> > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#51495) next »