This article mainly introduces about PHP reading external variables $GLOBALS, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
$one = 1;function demo(){ $two = 2; // 如果直接 $one 会在代码中报错 // 读取自定义函数demo外部的变量one - $GLOBALS['one'] $result = $two + $GLOBALS['one']; return $result; }echo demo(); // 3
function demo2(){ // 创建一个外部变量 $GLOBALS['aaa'] = 'aaaaaaaa'; echo 'demo2' . '<br/>'; }// 这样用会报错, 需要先调用demo2函数才行 //echo $aaa;demo2(); // demo2echo $aaa . '<br/>'; // aaaaaaaa
$one = 1;$two = 2;$five = 5;function demo(){ // 调用多个外部变量 global $one, $two, $five; return $one + $two + $five; }echo demo() . '<br/>'; // 8
Related recommendations:
Php reads data Basic operations
php method of reading the contents of BT seed files
The above is the detailed content of PHP reads external variable $GLOBALS. For more information, please follow other related articles on the PHP Chinese website!