What is the difference between $ var and $$ var?

4

What is the difference between a $ var and $$ var variable in PHP? How can it be used? Can you cite some examples of use?

    
asked by anonymous 01.05.2015 / 16:54

1 answer

5

$var is a variable and $$var is a "variable variable" whose name is the value of $ var.

see example:

<?php

    $var = "hoje";
    echo $var;
    $$var = 'ontem';
    echo $hoje;
?>

Using $$var is not very common (I almost see no use in applications) but I've seen it once: the code creator had used it to dynamically create variables with the $ _GET array key name.

see:

link

link

link

    
01.05.2015 / 16:56