提示: Notice: Undefined variable: fuck in D:\Web\htdocs\mt\Access\fuck.php on line 9 NULL
全局变量?
分享到: ------解决方案-------------------- function xx() { global $fuck; var_dump($fuck); } ------解决方案-------------------- $fuck = "ccaca"; function xx() { global $fuck; var_dump($fuck); } ------解决方案-------------------- 在函数体内定义的PHP Global变量,函数体外可以使用,在函数体外定义的global变量不能在函数体内使用。 ------解决方案-------------------- global $fuck;放在函数体内 ------解决方案-------------------- 全局变量:不在任何容器(函数、类)内定义的变量
函数或类方法中使用 全局变量 时需声明为全局变量(global)或通过 $GLOBALS 数组
请认真阅读手册中《变量范围》一节 ------解决方案-------------------- global $fuck; $fuck="sdfsa"; xx(); function xx(){ global $fuck; var_dump($fuck); }
在外定义的全局变量,在函数体内使用需要先用global声明 一下。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn