The meaning and role of PHP global

Source: Internet
Author: User
Tags php tutorial
All said not to write articles is not technical cattle people, next! To record my rookie growth course!

The scope of a variable is something that every programmer must consider, but in PHP it's a lot different from C + +! For example, the function inside and outside if the same variable name, but cannot be overwritten, want to refer to variables outside the function, need to use global. Next, look at the following demo:

$num =10;

function Test() {

$num = $num*10;

}

Test ();

Echo $num;

Output 10.

$num =10;

function Test() {

Global $num;

$num = $num*10;

}

Test ();

Echo $num;

Output 100. The program is not difficult, you understand it

The above describes the meaning and role of PHP global, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.