Home >Backend Development >PHP Tutorial >Interpretation of Global keyword reference for PHP global variables_PHP tutorial
This article will give you a brief introduction to the PHP global variable Global keyword reference. Although the comment is extremely short compared to the article, the principle is explained very clearly and is easy to understand, especially for It is worth summarizing for those who have some basic knowledge of language. Without further ado, let’s get down to the topic:
Quoting the explanation of $GLOBALS in the PHP manual:
Global variable: $GLOBALS
Note: $GLOBALS is available in PHP 3.0.0 and later.
An array consisting of all defined global variables. The variable name is the index into the array.
This is a "superglobal", or can be described as an automatic global variable.
In other words, $var1 and $GLOBALS['var1'] in the above code refer to the same variable, not 2 different variables!
Global variable example
The code is as follows
|
Copy code
|
||||||||||||||||||||||||
$pangbu = "pangbu";
echo $pangbu; }
demo();
In fact, global $pangbu ; is the abbreviation of $pangbu = &$_GLOBAL['pangbu '],
It means that $pangbu is a reference of $_GLOBAL['pangbu ']. As for how to use the reference, $pangbu is used. Some notes of my own I never figured out how to use global before. Although I knew how to use it, I was always confused. Now I finally figured it out. . In order to learn more about Global's applications, please see the following php case:
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 Previous article:PHP design pattern example singleton mode_PHP tutorialNext article:PHP design pattern example singleton mode_PHP tutorial Related articlesSee more |