Home >Backend Development >PHP Tutorial >小白求指点:自定义函数内调用另外一个函数里的全局变量,该如何写

小白求指点:自定义函数内调用另外一个函数里的全局变量,该如何写

WBOY
WBOYOriginal
2016-06-13 12:20:121086browse

小白求指点:自定义函数内调用另外一个函数里的全局变量,该怎么写啊
member.inc.php:

function marrbase(){<br />if(isset($_COOKIE["uname"]) && isset($_COOKIE["uid"])){<br />global $mbase;<br />$mbase_data = mysql_query("select * from dh_member where `id`=" . $_COOKIE["uid"] . " and `mck`=1");<br />if (!$mbase_data){die(mysql_error());exit();}<br />$mbase = mysql_fetch_array($mbase_data);<br />}<br />else{exit();}<br />}


我是这样写的:
<br />require_once("member.inc.php");<br />function supp(){<br />marrbase();<br />echo $mbase["email"]; exit();<br />}<br />


输出为空,小白求大神指点一下这个该怎么写才规范正确啊..


------解决思路----------------------
function supp() {
  global $mbase;
  marrbase();
  echo $mbase["email"]; exit();
}

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