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 to define a user function?
What is var_dump?
Define soundex()?
What is the difference between require_once and require in php?
What are the php functions?
Tell me how to retrieve a cookie value?
Hello Friends,I am seeking for a job in php having 9 months. exp.Please suggest any company openings.
Which MySQL function would you use to select a database?
What is put method in php?
Explain how to execute a php script using command line.
How do you pass a variable by value in php?
Is age a variable in research?
What are the uses of php language?
What are different types of Print Functions available in PHP?
What are the disadvantages of php?