当前位置:首页 > PHP教程 > PHP常见问题

PHP学习之预定义变量(实例讲解)

超全局变量

超全局变量–超全局变量是全部作用域中始终可用的内置变量

$globals

一个包含了全部变量的全局组合数组。变量的名字就是数组的键。
<?php
function test() {
  $foo = "local variable";
  echo '$foo in global scope: ' . $globals["foo"] . "n";
  echo '$foo in current scope: ' . $foo . "n";
}
$foo = "example content";
test();
?>
以上例程的输出类似于:
$foo in global scope: example content
$foo in current scope: local variable

$_server

<?php
echo "<pre>";
var_dump($_server);
output:
array (size=35)
 'http_host' => string 'localhost' (length=9)
 'http_connection' => string 'keep-alive' (length=10)
 'http_upgrade_insecure_requests' => string '1' (length=1)
 'http_user_agent' => string 'mozilla/5.0 (windows nt 10.0; wow64) applewebkit/537.36 (khtml, like gecko) chrome/53.0.2785.104 safari/537.36 core/1.53.3538.400 qqbrowser/9.6.12501.400' (length=153)
 'http_accept' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' (length=74)
 'http_referer' => string 'http://localhost/test/' (length=22)
 'http_accept_encoding' => string 'gzip, deflate, sdch' (length=19)
 'http_accept_language' => string 'zh-cn,zh;q=0.8' (length=14)
 'path' => string '%appcan_path%;d:workpython2.7;d:workpython2.7scripts;c:programdataoraclejavajavapath;c:windowssystem32;c:windows;c:windowssystem32wbem;c:windowssystem32windowspowershellv1.0;d:wampservermysqlbin;d:workjavatomcatbin;d:workmozilla firefoxfirefox.exe;d:workphantomjsbin;d:workchormedriver;c:windowssystem32configsystemprofile.dnxbin;c:program filesmicrosoft dnxdnvm;c:program filesmicrosoft sql server130toolsbinn;d:wampserverphp;c:programdatacomposersetupbi'... (length=607)
 'systemroot' => string 'c:windows' (length=10)
 'comspec' => string 'c:windowssystem32cmd.exe' (length=27)
 'pathext' => string '.com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.msc' (length=53)
 'windir' => string 'c:windows' (length=10)
 'server_signature' => string '' (length=0)
 'server_software' => string 'apache/2.4.18 (win64) openssl/1.0.2g php/5.6.19' (length=47)
 'server_name' => string 'localhost' (length=9)
 'server_addr' => string '::1' (length=3)
 'server_port' => string '80' (length=2)
 'remote_addr' => string '::1' (length=3)
 'document_root' => string 'd:/wampserver/www' (length=17)
 'request_scheme' => string 'http' (length=4)
 'context_prefix' => string '' (length=0)
 'context_document_root' => string 'd:/wampserver/www' (length=17)
 'server_admin' => string 'admin@example.com' (length=17)
 'script_filename' => string 'd:/wampserver/www/test/$_server.php' (length=35)
 'remote_port' => string '57305' (length=5)
 'gateway_interface' => string 'cgi/1.1' (length=7)
 'server_protocol' => string 'http/1.1' (length=8)
 'request_method' => string 'get' (length=3)
 'query_string' => string '' (length=0)
 'request_uri' => string '/test/$_server.php' (length=18)
 'script_name' => string '/test/$_server.php' (length=18)
 'php_self' => string '/test/$_server.php' (length=18)
 'request_time_float' => float 1510122616.201
 'request_time' => int 1510122616

以上这篇php学习之预定义变量(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持硕编程。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐