PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
stubarny
Forum Newbie
Posts: 10 Joined: Thu Jul 27, 2006 12:53 pm
Post
by stubarny » Tue Feb 27, 2007 3:10 pm
Hi everyone,
How do I create a variable name made of other variable names and then query it?
i.e. what do i have to replace "${$car}" with in the code below to make it work?
Code: Select all
$car = ford;
$ford = good;
if ( ${$car} == 'good' ) # This line doesn't work!
{
echo "it works!";
}
Thanks for your help!
Stu
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Feb 27, 2007 4:02 pm
Code: Select all
[feyd@home]>php -r "$car = 'ford'; $ford = 'good'; var_dump(${$car} == 'good');"
bool(true)
Sure works for me.