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
How can I learn php fast?
Inside a php function, what param needs to be set in order to access a global variable?
What are the 5 types of variables?
Write a hello world program using variable?
Does php support inheritance?
Do I need apache for php?
What is the difference between a session and cookies?
How can we submit a form without using submit buttons?
What is the use of limit in mysql?
Is server side a session?
What is mvc in php?
Tell me how can we connect to a mysql database from a php script?
What changes I have to do in php.ini file for file uploading?
Why php is used with mysql?
Write a program to find a string is palindrome or not?