How can global variables be created and accessed in PHP?
Global variables in PHP can be created by using the global keyword to declare a variable within a function as global. This allows the variable to be accessed and modified outside of the function scope. To access a global variable, you can simply refer to it using the global keyword followed by the variable name.
$globalVar = "I am a global variable";
function myFunction() {
global $globalVar;
echo $globalVar;
}
myFunction(); // Output: I am a global variable