What is difference between $x and $$x

Answer Posted / deepesh mehta

This type of variable diclearation is called "Variable
variables".
Sometimes it is convenient to be able to have variable
variable names. That is, a variable name which can be set
and used dynamically. A normal variable is set with a
statement such as:

$x = 'hello';

A variable variable takes the value of a variable and
treats that as the name of a variable. In the above
example, hello, can be used as the name of a variable by
using two dollar signs. i.e.

$$x = 'world';

At this point two variables have been defined and stored in
the PHP symbol tree: $a with contents "hello" and $hello
with contents "world". Therefore, this statement

echo "$x ${$x}";

produces the exact same output as:

echo "$a $hello";

i.e. they both produce: hello world.

Is This Answer Correct ?    34 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What percentage of websites use php?

504


How would you open a directory for reading in php?

572


Explain some most commonly use string functions in php?

505


What is the purpose of using php?

512


How do you measure variables?

524






What is php variable?

523


What is a string in r?

514


How cookies are transported from servers to browsers?

518


How to remove an empty directory?

579


What is a composer?

534


Does php need to be installed?

505


How to replace a text in a string with another text in php?

520


Tell me what is the use of isset() in php?

545


Tell me what is the difference between get and post?

477


Is php used for frontend or backend?

532