The scope of variables in PHP
What is the scope of variables?
Variable scope refers to the part of the program where the variable can be accessed.
Variable scope in PHP
There are three variable scopes in PHP:
1. Local scope
Local variables are only visible within the function in which they are declared. If you declare a variable within a function, the variable is not available outside that function.
2. Function parameter scope
Function parameters are visible inside the function, but not visible outside the function.
3. Global scope
Global variables can be accessed from any part of the program. Global variables need to be declared using the global
keyword.
Factors affecting variable scope
global
Use of keywordsExample
1 2 3 4 5 6 7 8 9 10 11 12 |
|
In the example:
$local
Only available within the myFunction()
function. $param
Available only within the myFunction2()
function. $global
can be used in any part of the program. The above is the detailed content of How to create a horizontal colon in vertical text in PS. For more information, please follow other related articles on the PHP Chinese website!