What is the difference between a $ var and $$ var variable in PHP? How can it be used? Can you cite some examples of use?
What is the difference between a $ var and $$ var variable in PHP? How can it be used? Can you cite some examples of use?
$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: