global is a global variable in PHP. This global is just a global variable on the page. For variables outside of functions, we can directly use the global declaration in the function to obtain the value of the variable.
Example
The code is as follows | Copy code | ||||||||||||||||||||||||||||
$a=12;
function fn() {
$a+=12; }
?> Output result: $a=24 Summary: Global variables defined within the function body can be used outside the function body, but global variables defined outside the function body cannot be used inside the function body,
global problem analysis: Question: I have defined some variables ($a) in config.inc.php, and include ("config.inc.php") outside the function in other files. These variables $a need to be used inside the function. If Without a statement, echo $a will not print anything. Therefore, global $a is declared, but there are many functions and many variables. You can't declare it like this repeatedly, right? If there is any good solution, please give me some advice.
Previous article:Study Notes on Cookie and Session Application in PHP_PHP Tutorial
Next article:Introduction to php regular expressions_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
When adding sublime3 to compile system php, use the PHP toolbox, cmd php -v is useless
From 1970-01-01 08:00:00
0
0
0
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
|