Does php support global variables? How can this problem be solved?

Source: Internet
Author: User
Does php support global variables? Can you define a global variable, assign it different values on different pages, and then call it. & Nbsp; for example, define var = 0 in. & nbsp; var = 1; & nbsp; includec. php in B. & nbsp; var = 2; & nbsp; Dec. php in c. does p php support global variables?
Can you define a global variable, assign it different values on different pages, and then call it.

For example, define var = 0
In a. php
Var = 1;
Include c. php
In B. php
Var = 2;
Include c. php
Judge in c. php
If (var = 1)
Include c1.php
If (var = 2)
Include c2.php
Else
...

I tried to write it like this. it seems no.
You can write this variable into the session.

------ Solution --------------------
No. PHP does not have global variables. it can be stored and read in a database or file.
------ Solution --------------------
There are global variables
For example
$ Var = 0; written in config. php

In c. php, include_once ('config. php ');
Then you can use the $ var variable.

However, if you want to use $ var in the function
Add global $ var;
------ Solution --------------------
Discussion

There are global variables
For example
$ Var = 0; written in config. php

In c. php, include_once ('config. php ');
Then you can use the $ var variable.

However, if you want to use $ var in the function
Add global $ var;

------ Solution --------------------
There are many. Session is one of them.
------ Solution --------------------
Text games?
Global
All variables other than functions and classes are global variables.

Leave a variable that exists independently in the php program. php is called a system variable. Read-only

$ _ GET, $ _ POST, and $ _ SESSION are super global variables.

------ Solution --------------------
The session in php can be used to set global variables, store the values in them, and the values are valid until you delete them (cookie has similar practices)
------ Solution --------------------
It is defined in a public file and then included in all files. this variable is a global variable...

Sessions, databases, and hidden domain values can also be global variables.
------ Solution --------------------
Of course.
------ Solution --------------------
Saving variables to the object is similar to the php Singleton mode. isn't that all right? We can change the value or call it globally.
------ Solution --------------------
Discussion

Text games?
Global
All variables other than functions and classes are global variables.

Leave a variable that exists independently in the php program. php is called a system variable. Read-only

$ _ GET, $ _ POST, and $ _ SESSION are super global variables.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.