Quick question

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

Post Reply
stubarny
Forum Newbie
Posts: 10
Joined: Thu Jul 27, 2006 12:53 pm

Quick question

Post by stubarny »

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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

[feyd@home]>php -r "$car = 'ford'; $ford = 'good'; var_dump(${$car} == 'good');"
bool(true)
Sure works for me.
Post Reply