$cars = $row->CARS; needs to be $cars = $row->$CARS;

I am using this code and need to choose cars using a PHP variable so effectively I need to write:

$cars = $row->$CARS;

But it will not let me use the cars variable. How do I choose/write the variable using PHP? Why must it be plain text? I need the PHP variable instead!

Thanks.

Try evaluating the variable like so

$cars = $row->{$CARS};

that gets rid of the errors however I am actually using 2 variable names to lookup another 1 variable name where the 1 variable name is made up of the 2 variable names.

Heres an example:

Table 1 has 2 variables: Ca, rs
Table 2 has 1 variable: Cars

So in effect I am asking for Ca and rs so I am trying to do this:

$cars = $row->{$variable1}{$variable2};

variable1=ca
variable2=rs

so it asks for cars in the other table

which should evaluate cars in the other table.

Another way of asking this question is how can I create another variable reference from 2 others.

If the variables are 1 and 3 I get 13
If the variables are 2 and 24 I get 224
If the variables are 5 and 6 I get 56 and so on.

How do I create the new variable name from the original 2?

${$variable1}{$variable2}

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.