PHPGlobal variables are used to define global variables on the current page. PHPGlobal variables will find many problems in practical applications that need to be constantly improved. In this article, we provide some specific PHP Global variables for the problems that occur in PHPGlobal variables. in actual application, we will find many problems that need to be constantly improved. In this article, we provide some specific solutions to the problems with PHP Global variables.
1: PHP Global variables define Global variables.However, this global variable is not applied to the entire website, but to the current page, including all files of include or require.
The code is as follows:
$ A = 123;
Function aa ()
{
Global $;
// If $ a is not defined as a global variable
The function body cannot access $.
Echo $;
}
Aa ();
Conclusion: PHP Global variables defined in the function body can be used in vitro. global variables defined in the function body cannot be used in the function body,
The code is as follows:
$ Glpbal $ a; $ a = 123; function f () {echo $ a; // error ,}
Let's take a look at the following example:
The code is as follows:
Function f ()
{
Global $;
$ A = 123;
}
F ();
Echo $ a; // correct, which can be used
2: Analysis of PHP Global variables:
Question: In config. inc. php defines some variables ($ a). in other files, the function external include ("config. inc. php "), the function needs to use these variables $ a internally. If no declaration is made, echo $ a cannot print anything. Therefore, we declare global $ a. But there are a lot of functions and many variables that cannot be repeatedly declared? Please advise if you have any good solutions.
Answer1: first in config. inc. define a constant in php: define (constant name, constant value), and then require 'config. inc. php, and then you can directly use this constant in this file.
Answer2: I also have a way to define an array, such as $ x [a], $ x, so that we only need to declare a global $ x.
Answer3: I tried your method. no.
Answer4: modify your php. ini file.
Set PHP Global variable to on
Http://www.bkjia.com/PHPjc/327470.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327470.htmlTechArticlePHP Global variables in practical application will find that many problems need to be constantly improved. In this article, we have provided some specific problems with the PHP Global variable...