Home >Backend Development >PHP Tutorial >Example explanation of predefined variables for PHP learning

Example explanation of predefined variables for PHP learning

jacklove
jackloveOriginal
2018-07-02 18:03:451516browse

下面小编就为大家分享一篇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()用法详解

The above is the detailed content of Example explanation of predefined variables for PHP learning. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn