$var is just a variable with name var, $$var takes string from variable $var and finds variable of that name. Example will be better: $var = 'fruit'; $$var = 5; echo $fruit; // echoes 5 Is that clear?
$$var uses the value of the variable whose name is the value of $var. It allows you to have a "variable variable" - the program can create the variable name the same way it can create any other string. That's helpful in situations like $item1, $item2, etc. The program can set $var equal to "item" plus a number, then use the value in that variable by referencing $$var.
Say you have this. <?php $var = "chocolate"; $chocolate = "is yummy"; echo $$var; ?> It will echo "is yummy"
$$ represents a variable variable. Here's how they work $foo = 'bar'; $var = 'foo'; echo $var; // foo echo $$var; //bar echo $foo; //bar You first assign the value of a variable, $var, to the name of another variable. When you set $var to a value, it will replace that variable name with the value of the variable you provide it. $test = 'asdf'; $$test = 'I am changing asdf\'s value!'; echo $$test; // I am changing asdf's value! echo $test; // asdf echo $asdf; // I am changing asdf's value!
It's pretty handy, you can even have variable-variable-variables like so: $$$var, if you wanna be crazy, that is.
finally at the end, It will be confusing and we will not be sure for what we created such a variable....$$$$var Pretty insane. I Understand it in code wise, But, can some one give me some practical use. In what scenarios we will be using such variables??
$var is just a variable with name var, $$var takes string from variable $var and finds variable of that name. Example will be better: $var = 'fruit'; $$var = 5; echo $fruit; // echoes 5 this example is best
It is used when you need flexibile variable naming... In this case, it is not used much. More used is version with magic properties in objects...
I have never heard of such thing called as magical property. but was curious to know what it is all about and googled a bit. Found this link very interesting... worth taking a look at it http://forums.darklordpotter.net/showpost.php?p=426882&postcount=89
Official php doc will be better http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members