<?php
//函数内部无法访问全局变量
$room = 20;
function showrooms()
{
echo $room;
}
showrooms();
echo "<br>";
echo $room."间房间。";
echo "<br>";
//函数内部访问全局变量请使用global
$dog = 20;
function showdogs()
{
global $dog;
echo $dog."只狗。";
echo "<br>";
}
showdogs();
echo $dog."条狗。";
echo "<br>";
//函数内部可以使用$GOLBALS数组访问全局变量
$bird = 20;
function showbirds()
{
$bird = $GLOBALS['bird'];
echo $bird."支鸟。";
echo "<br>";
}
showbirds();
echo $bird."鸟。";
echo "<br>";