Home  >  Article  >  Backend Development  >  php learning 2

php learning 2

WBOY
WBOYOriginal
2016-07-30 13:29:25933browse
  1. Scope
    The area where variables can be accessed.
    Scope in js:
    Global scope: can be used anywhere (outside and inside functions)
    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, the outside cannot access the inside
Local scope: can only be used inside the function, and cannot access the outside
Global scope refers to variables defined outside the function, and local scope refers to variables defined inside the function
A. You can use $GLOBALS[‘global scope variables’] in the local scope to access the global scope

B. PHP also provides a keyword: global
Global copies the address of the variable in the global scope, then creates a new variable name with the same name in the local scope, and assigns the external address to the local variable.
Syntax: global variable name;
Variable name = value;

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced PHP Learning 2, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn