PHP global and local variables

Source: Internet
Author: User
How can I use the local variable $ y in row 19th in the global environment? is there any way to use the local variable in row 5th globally? the reason for this is that I started to learn PHP wants to know if there is such a method. thank you.

How can I use local variables in the global environment?

$ Y in row 19th is undefined. Is there any way to use local variables in row 5th globally?

The reason for this question is that I started learning PHP and want to know if there is such a method. thank you.

Reply content:

How can I use local variables in the global environment?

$ Y in row 19th is undefined. Is there any way to use local variables in row 5th globally?

The reason for this question is that I started learning PHP and want to know if there is such a method. thank you.

Global $ y;
$ Y = 10;

Global $ adfds = & y;

You can try this one, I don't know;

Either of the two methods is to add the global keyword, global $ y; $ y = 10; the second is to put it in the ultra-global Array $ GLOBALS, for example, $ GLOBALS ['Y'] = 10

If you have a global variable $ a first, then reference it in a local scope, and declare it with the global keyword.
(If $ a is used in the function, a local $ a is created by default instead of a global one ).
This is the official global page: (we suggest you read the official manual first when you encounter any problems)
Http://www.php.net/manual/zh/language.va...

But your question is, how does one change the local variable $ y in the function into a global one?
The answer is, there is no way .... Php does not have this function... ===
Don't worry, you don't need to do that. It is rarely used to write programs, even global keywords.

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.