开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜