The scope determines where a variable can be accessed. PHP has three types of variable scope:
Local Scope: Accessible only within a function.
Global Scope: Accessible everywhere, except inside functions (unless declared global).
Static Variables: Retain their value between function calls.
Example:
<?php
// Global scope
$name = "John";
function displayName() {
// Access global variable inside a function
global $name;
echo $name;
}
displayName(); // Outputs: John
?>
Variable Variables
You can use the value of one variable as the name of another variable.