tags:

views:

42

answers:

2

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);

All help appreciated!!

A: 

Use $$text.
You wrote it with parenthesis, which is not the correct syntax.

kiamlaluno
+6  A: 

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};
zombat