function testfunction() {
echo $globals[php_self];
}
testfunction();
// 本程序使用全局定义
function testfunction() {
global $s;
echo $s;
}
$s='this is www.111cn.net';
testfunction();
// 静态变量的例子
function testfunction() {
static $mystr;
$mystr.=111cn.net;
echo $mystr.
;
}
testfunction(); // 111cn.net
testfunction(); // 111cn.net111cn.net
testfunction(); // 111cn.net111cn.net111cn.net
// 普通变量
function testfunction() {
$mystr.=www.111cn.net;
echo $mystr.
;
}
testfunction(); // www.111cn.net
//下面我们来简单的介绍一下php中的超级全局变量有那些
//$globals 包含一个引用指向每个当前脚本的全局范围内有效的变量,实例
$globals['site'];
//$_server 变量由 web 服务器设定或者直接与当前脚本的执行环境相关联
echo $_server['document_root'];
//$_get url 请求提交至脚本的变量
echo $_get['ac']
//$_post http post 方法提交至脚本的变量
echo $_post['ab']
//$_cookie http cookies 方法提交至脚本的变量
setcookie('load','www.111cn.net',time()+3600*24,'/','192.168.0.110');
$cookis = $_cookie['loaddomain'];
//$_files http post 文件上传而提交至脚本的变量
输出值:
print_r( $_files['file'] ); array
(
[name] => 45457.jpg
[type] => image/pjpeg
[tmp_name] => c:windowstempphpd7.tmp
[error] => 0
[size] => 10974
)
//$_env 不推荐使用
//$_request 由get,post 和 cookie 机制提交至脚本的变量,因此该数组并不安全并且效率不高。
$_request['bb'] //会自动提交过来的数据是post,get形式
