Php learning log-variable scope

Source: Internet
Author: User
: This article mainly introduces the php learning log-variable scope. if you are interested in the PHP Tutorial, refer to it. 1. access within the global function Global variables

 

If the myTest function does not use global, it cannot be used.

PHP adds allGlobal variablesStored in a table named $ GLOBALS [Index.IndexSave the variable name. This array can be accessed inside the function or directly used to updateGlobal variables. For example, $ GLOBALS ['Y'] = $ GLOBALS ['x'] + $ GLOBALS ['Y']

2. Static when a function is completed, all its variables are usually deleted. However, sometimes you want a local variable not to be deleted.

Function myTest () {static $ x = 0; echo $ x; $ x ++;} myTest (); 012

Each time a function is called, the variable retains the value of the previous call of the function. This variable is still a local variable of the function.

The above introduces the php learning log-variable scope, including the global variables, and hopes to help those who are interested in the PHP Tutorial.

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.