0

This may sound confusing:

$myVar = "Helloooo!";
$text = "myVar";

How could i call $myVar from just the fact $text is filled with the variable name, perhaps this ? (it doesnt work though)

echo $($text);
2

1 Answer 1

5

PHP has a feature called "variable variables", that works exactly like you need it to.

You can use it almost like you posted, but without the brackets:

echo $$text;

The best notation is using curly braces however, as that removes ambiguities when dealing with arrays.

echo ${$text};
Sign up to request clarification or add additional context in comments.

Comments

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.