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:
Related labels:
source:php.cn
Previous article:PHP design pattern example singleton mode_PHP tutorial
Next article:PHP study notes: php variable usage_PHP tutorial
Statement of this Website
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
Latest Articles by Author
Latest Issues
Group MySQL results by ID for looping over
I have a table with flight data in mysql. I'm writing a php code that will group and displ...
From 2024-04-06 17:27:56
0
1
406
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|