what is “$$” in PHP

回眸只為那壹抹淺笑 提交于 2019-11-26 18:22:22

问题


I saw this code

if (is_null($$textVarName)) {
$$textVarName = $_defaultTexts[$type];
}

what is code "$$" ?


回答1:


It's evil is what it is.

That will take the value that's in $textVarName and use that as a variable name. For example:

$foo = 'hello';
$hello = 'The Output';
echo $$foo; // displays "The Output"



回答2:


foreach($_POST as $key=>$value)$$key=$value;

now, automagically, if the previous form had a field named 'username' you now have a variable called $username that holds the value submitted in the form. not the greatest or secure method, but when you have a pocket full of nails, this is a heck of a hammer

this is pretty bad practice and is never encouraged but all PHP coders I know secretly sorta like it.




回答3:


For reference, see: http://php.net/manual/en/language.variables.variable.php



来源:https://stackoverflow.com/questions/4169882/what-is-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!