[PHP] Variable with name of other variable – “variable variables”

[PHP] Variable with name of other variable – “variable variables”

When you write in PHP $$name, parser treats it as variable, wchich name is value of $name – it works like pointer:

<? 
$var1 = 'test1';
$var2 = 'test2';
$a = 'var1';
echo $$a.'<br>';
$a = 'var2';
echo $$a;
?>

output:

test1
test2

Leave a Reply

Your email address will not be published. Required fields are marked *