Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The PHP Global variable defines what the global variable of the current page is.

2025-03-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail about PHP Global variable definition of the current page of the global variable is what, the content of the article is of high quality, so the editor to share with you to do a reference, I hope you have a certain understanding of the relevant knowledge after reading this article.

PHP Global variable in the practical application will find many problems that we need to constantly improve and deal with. In this article, we give some specific solutions to the problems with PHP Global variables.

The function of the 1:PHP Global variable is to define a global variable, but this global variable is not applied to the entire site, but to all files on the current page, including include or require

$axi123

Function aa ()

{

Global $a

/ / if you do not define $an as the global variable

The body of the function cannot access $a

Echo $a

}

Aa ()

Summary: the PHP Global variable defined in the function body can be used outside the function body, while the global variable defined outside the function body cannot be used in the function body.

$glpbal $a; $aq123; function f () {echo $a; / / error,}

Take a look at the following example

Function f () {global $a; $aq123;} f (); echo $a; / / correct, you can use

Resolution of 2:PHP Global variable problem:

Question: I have defined some variables ($a) in config.inc.php, external include ("config.inc.php") in other files, need to use these variables $an inside the function, and echo $a can't print anything if it's not declared. So declare global $a, but there are a lot of functions and a lot of variables, and you can't declare it over and over again, right? If there is any good solution, please give me some advice.

Answer1: first define the constant in config.inc.php: define (constant name, constant value), then require 'config.inc.php', where you need it, and then you can use the constant directly in this file.

Answer2: I also have an idea, which is to define an array, such as $x [a], $x, then just declare one global $x.

Answer3: I tried your method. I can't do it.

Answer4: change your php.ini file.

Set the PHP Global variable to on

On the PHP Global variable definition of the current page of the global variable is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report