Page 1 of 1

Quick question

Posted: Tue Feb 27, 2007 3:10 pm
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

Posted: Tue Feb 27, 2007 4:02 pm
by feyd

Code: Select all

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