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
Does php need a closing tag?
What is a php 5?
How to get number of days between two given dates using PHP?
How do I display php errors?
How values in arrays are indexed?
What is php's mysqli extension?
How can you submit a form without a submit button?
What is php glob?
How to close a session properly?
What is the use of strpos in php?
What is php.ini & .htacess file?
Should I learn php before wordpress?
How to convert a character to an ascii value?
How can I use single quotes in single quotes in php?
How to repeat a string to a specific number of times in php?