Re: variable question...

From: Date: Tue, 16 Apr 2002 08:42:45 +0000
Subject: Re: variable question...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-93130@lists.php.net to get a copy of this message
"Phil Schwarzmann" <pschwar@jhmi.edu> wrote: > Let's say I a variable called $var1 and it's values is "one" > > ...I want to access them by doing something like this... > > $i = 1; > if ("var".$i == "one") echo "Hello!"; > > ...I want the combination of "var" and $i to equal $var1 > > How do I do this?? > The code I just wrote will not print out "Hello!" You can use variable variable names by adding another '$'. so if $i == 1 and $var1 == "one", you can do this: $var_name = "var".$i; if($$var_name == "one") echo "Hello!"; That should work, Justin

« previous php.general (#93130) next »