Home > Article > Web Front-end > How to create a horizontal colon in vertical text in PS
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
<code class="php">// 局部作用域 function myFunction() { $local = "This is a local variable"; } // 函数参数作用域 function myFunction2($param) { echo $param; } // 全局作用域 $global = "This is a global variable";</code>
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!