ModifyMe
asked on
What are Dynamic Variables or Variable Variables?
Hey all,
Well, by the title you can tell I am not a CS major. But I've heard a few things about these types of variables and my internet searching seems to be coming up short on a decent 'Dynamic Variables 101' topics.
So any elementary style explanation would be greatly appreciated.
Thank you.
Well, by the title you can tell I am not a CS major. But I've heard a few things about these types of variables and my internet searching seems to be coming up short on a decent 'Dynamic Variables 101' topics.
So any elementary style explanation would be greatly appreciated.
Thank you.
What was the context where you heard these terms ?
ASKER
In a PHP tutorial for development.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A dynamic variable is a variable whose address is determined when the program is run. In contrast, a static variable has memory reserved for it at compilation time.
@deva1983 : not in the case of PHP ;)
Hi All,
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
<?php
$a = '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.
<?php
$$a = '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:
<?php
echo "$a ${$a}";
?>
produces the exact same output as:
<?php
echo "$a $hello";
?>
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
<?php
$a = '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.
<?php
$$a = '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:
<?php
echo "$a ${$a}";
?>
produces the exact same output as:
<?php
echo "$a $hello";
?>
@ashokadi : is that a direct copy from the page I linked to earlier ?
@Infinity08,Yes information is from that only but i didn't check your message previously,
ASKER
Thanks.
Also, can you elaborate from your response to deva1983?
Also, can you elaborate from your response to deva1983?