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

jacklove
发布: 2023-04-02 08:38:01
原创
1461 人浏览过

下面小编就为大家分享一篇PHP学习之预定义变量(实例讲解),具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

超全局变量

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

$GLOBALS

一个包含了全部变量的全局组合数组。变量的名字就是数组的键。
登录后复制

<?php
function test() {
  $foo = "local variable";
  echo &#39;$foo in global scope: &#39; . $GLOBALS["foo"] . "\n";
  echo &#39;$foo in current scope: &#39; . $foo . "\n";
}
$foo = "Example content";
test();
?>
以上例程的输出类似于:
$foo in global scope: Example content
$foo in current scope: local variable
登录后复制

$_SERVER

<?PHP
echo "<pre class="brush:php;toolbar:false">";
var_dump($_SERVER);
output:
array (size=35)
 &#39;HTTP_HOST&#39; => string &#39;localhost&#39; (length=9)
 &#39;HTTP_CONNECTION&#39; => string &#39;keep-alive&#39; (length=10)
 &#39;HTTP_UPGRADE_INSECURE_REQUESTS&#39; => string &#39;1&#39; (length=1)
 &#39;HTTP_USER_AGENT&#39; => string &#39;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&#39; (length=153)
 &#39;HTTP_ACCEPT&#39; => string &#39;text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8&#39; (length=74)
 &#39;HTTP_REFERER&#39; => string &#39;http://localhost/test/&#39; (length=22)
 &#39;HTTP_ACCEPT_ENCODING&#39; => string &#39;gzip, deflate, sdch&#39; (length=19)
 &#39;HTTP_ACCEPT_LANGUAGE&#39; => string &#39;zh-CN,zh;q=0.8&#39; (length=14)
 &#39;PATH&#39; => string &#39;%APPCAN_PATH%;D:\Work\python2.7\;D:\Work\python2.7\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;D:\wampserver\mysql\bin;D:\Work\JAVA\tomcat\bin;D:\Work\Mozilla Firefox\firefox.exe;D:\Work\phantomjs\bin;D:\Work\chormedriver;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\wampserver\php;C:\ProgramData\ComposerSetup\bi&#39;... (length=607)
 &#39;SystemRoot&#39; => string &#39;C:\WINDOWS&#39; (length=10)
 &#39;COMSPEC&#39; => string &#39;C:\WINDOWS\system32\cmd.exe&#39; (length=27)
 &#39;PATHEXT&#39; => string &#39;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC&#39; (length=53)
 &#39;WINDIR&#39; => string &#39;C:\WINDOWS&#39; (length=10)
 &#39;SERVER_SIGNATURE&#39; => string &#39;&#39; (length=0)
 &#39;SERVER_SOFTWARE&#39; => string &#39;Apache/2.4.18 (Win64) OpenSSL/1.0.2g PHP/5.6.19&#39; (length=47)
 &#39;SERVER_NAME&#39; => string &#39;localhost&#39; (length=9)
 &#39;SERVER_ADDR&#39; => string &#39;::1&#39; (length=3)
 &#39;SERVER_PORT&#39; => string &#39;80&#39; (length=2)
 &#39;REMOTE_ADDR&#39; => string &#39;::1&#39; (length=3)
 &#39;DOCUMENT_ROOT&#39; => string &#39;D:/wampserver/www&#39; (length=17)
 &#39;REQUEST_SCHEME&#39; => string &#39;http&#39; (length=4)
 &#39;CONTEXT_PREFIX&#39; => string &#39;&#39; (length=0)
 &#39;CONTEXT_DOCUMENT_ROOT&#39; => string &#39;D:/wampserver/www&#39; (length=17)
 &#39;SERVER_ADMIN&#39; => string &#39;admin@example.com&#39; (length=17)
 &#39;SCRIPT_FILENAME&#39; => string &#39;D:/wampserver/www/test/$_SERVER.php&#39; (length=35)
 &#39;REMOTE_PORT&#39; => string &#39;57305&#39; (length=5)
 &#39;GATEWAY_INTERFACE&#39; => string &#39;CGI/1.1&#39; (length=7)
 &#39;SERVER_PROTOCOL&#39; => string &#39;HTTP/1.1&#39; (length=8)
 &#39;REQUEST_METHOD&#39; => string &#39;GET&#39; (length=3)
 &#39;QUERY_STRING&#39; => string &#39;&#39; (length=0)
 &#39;REQUEST_URI&#39; => string &#39;/test/$_SERVER.php&#39; (length=18)
 &#39;SCRIPT_NAME&#39; => string &#39;/test/$_SERVER.php&#39; (length=18)
 &#39;PHP_SELF&#39; => string &#39;/test/$_SERVER.php&#39; (length=18)
 &#39;REQUEST_TIME_FLOAT&#39; => float 1510122616.201
 &#39;REQUEST_TIME&#39; => int 1510122616
登录后复制

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

您可能感兴趣的文章:

PHP 获取某年第几周的开始日期和结束日期的实例讲解

PHP接口多继承及tarits实现多继承效果的方法_php技巧

thinkPHP5框架数据库连贯操作之cache()用法详解

以上是PHP学习之预定义变量实例讲解的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!