How does the scope of functions in PHP impact the usage of variables within them?
The scope of functions in PHP determines where variables can be accessed and modified within the code. Variables declared outside of a function have global scope and can be accessed from anywhere in the code, while variables declared within a function have local scope and can only be accessed within that function. To use a global variable within a function, you can use the `global` keyword to explicitly declare the variable as global.
$globalVar = "I am a global variable";
function myFunction() {
global $globalVar;
echo $globalVar;
}
myFunction(); // Output: I am a global variable