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
What's the difference between using mysql_ functions and pdo?
How to generate a character from an ascii value?
Tell me what type of operation is needed when passing values through a form or an url?
How to replace a substring in a given string in php?
Tell me how can we connect to a mysql database from a php script?
How to calculate the difference between two dates using php?
What does addslashes do in php?
Explain the difference between require() and require_once()?
Which operator is used to combine string values in php?
Tell me how to find current date and time?
What is difference between sql and php?
how to use http headers inside php? Write the statement through which it can be added?
What is rest api in php?
How can you encrypt password using php?
Tell me how do I escape data before storing it into the database?