不羁
Follow

After following, you can keep track of his dynamic information in a timely manner

Course notes
  • Courses in the relevant section:How to access global variables in a function?

    //方法1: 使用global关键字声明一个全局变量 function catching1(){ global $thief; return isset($thief) ? '1抓住: '.$thief : '没有抓住'; } echo catching1(); echo '<hr>'; // 方法2:使用超全局变量$GLOBALS //超全局变量,其实也是全局变量,只是不需要用户定义,而是由系统事先定义好的,用户可以直接使用 //函数外部定义的全局变量,会自动成为超全局变量$GLOBALS数组中的一个值: function catching2(){ $thief = $GLOBALS['thief']; return isset($thief) ? '2抓住: '.$thief : '没有抓住'; } echo catching2(); echo '<hr>'; //方法3: 使用函数传参的方式 function catching3($a) { return isset($a) ? '3抓住: '.$a : '没有抓住'; } echo catching3($thief);

    2018-11-270个赞