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's the difference between using mysql_ functions and pdo?

517


How to generate a character from an ascii value?

562


Tell me what type of operation is needed when passing values through a form or an url?

529


How to replace a substring in a given string in php?

541


Tell me how can we connect to a mysql database from a php script?

503






How to calculate the difference between two dates using php?

538


What does addslashes do in php?

529


Explain the difference between require() and require_once()?

524


Which operator is used to combine string values in php?

498


Tell me how to find current date and time?

537


What is difference between sql and php?

543


how to use http headers inside php? Write the statement through which it can be added?

504


What is rest api in php?

510


How can you encrypt password using php?

513


Tell me how do I escape data before storing it into the database?

521