PHP How do I retrieve this value?
I have a situation where I need to get the value of a variable, where the name od the variable is passed in a string in a second variable.
For example
$abc = 'the value I want';
$def = 'abc';
Where $def is the only variable name I can garrauntee being accessible. In this situation how can I get the value of $abc.
Cheer开发者_Python百科s
echo $$def;
does the job.
Use it very sparsely though, it makes code difficult to maintain!
PHP can have variable variables, like this:
${$def}
It also, incidentally, can have variable object and function names.
You can use "$$def" for this.
Examples: http://php.net/manual/en/language.variables.variable.php
精彩评论