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. source:php.cn
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
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>
|