Re: Extracting Array value as variable

From: Date: Mon, 07 May 2001 17:32:37 +0000
Subject: Re: Extracting Array value as variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-51782@lists.php.net to get a copy of this message
On Fri, May 04, 2001 at 08:08:11PM -0400, 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? It always amazes me that people are so afraid of simply trying. Yes, there is a way to do this. Simple test code that does work: <?php $broccoli=1; $tomatoes=2; $veg[0] = "broccoli"; $veg[1] = "tomatoes"; echo $$veg[0]." ".$$veg[1]; // This will print 1 2 ?> -- Jason Stechschulte jpstech@unoh.edu -- Anyway, my money is still on use strict vars . . . -- Larry Wall in <199710011704.KAA21395@wall.org>

« previous php.general (#51782) next »