Php Dynamic Variable

454 views Asked by At
$X['high'] = 1234;
$var = array("X","high");

This is working:

$temp = $$var[0];
$temp = $temp[$var[1]];
echo $temp;

But this isn't working:

echo $$var[0][$var[1]];

Why? How can i make it works?

1

There are 1 answers

1
u_mulder On BEST ANSWER

You should explain to php parser how you want this statement to be parsed:

echo ${$var[0]}[$var[1]];

Without brackets you will have:

php7

Notice: Array to string conversion in /in/cvZqc on line 5

Notice: Undefined variable: Array in /in/cvZqc on line 5

php5

Warning: Illegal string offset 'high' in /in/cvZqc on line 5

Notice: Array to string conversion in /in/cvZqc on line 5

Sample link.