0
$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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Make it perfect and show , before and after PHP7 syntax, or just notice that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.