Scope of PHP

Source: Internet
Author: User

This article mainly introduces the scope of PHP, has a certain reference value, now share to everyone, the need for friends can refer to

The area to which the variable can be accessed.
JS in scope:
Global scope: can be used anywhere (outside the function and inside the function)
Local scope: Can only be used inside a function

PHP also has two scopes: global scope and local scope
Global scope: can only be used outside the function
Local scope: Can only be used inside a function

Global scope refers to a variable defined outside a function, and a local scope refers to a variable defined inside a function
Internal cannot access external

External cannot access internal

Global scope can be accessed using $globals[' global scope variable ' in a local scope

Note: $GLOBALS is a variable that refers to the global scope itself

PHP also provides a keyword: global
Global is the address of the variable of the global scope, replicates it, and creates a new variable name with the same name within the local scope, assigning the external address to the local variable.
Syntax: global variable name;
Variable name = value;

The area to which the variable can be accessed.
JS in scope:
Global scope: can be used anywhere (outside the function and inside the function)
Local scope: Can only be used inside a function

PHP also has two scopes: global scope and local scope
Global scope: can only be used outside the function
Local scope: Can only be used inside a function

Global scope refers to a variable defined outside a function, and a local scope refers to a variable defined inside a function
Internal cannot access external

External cannot access internal

Global scope can be accessed using $globals[' global scope variable ' in a local scope

Note: $GLOBALS is a variable that refers to the global scope itself

PHP also provides a keyword: global
Global is the address of the variable of the global scope, replicates it, and creates a new variable name with the same name within the local scope, assigning the external address to the local variable.
Syntax: global variable name;
Variable name = value;

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.