How can a variable be made globally accessible in PHP?

To make a variable globally accessible in PHP, you can use the global keyword to declare the variable within a function as global. This allows the variable to be accessed outside of the function scope. By using the global keyword, you can ensure that the variable is available throughout the entire script.

$globalVar = "I am a global variable";

function testFunction() {
    global $globalVar;
    echo $globalVar;
}

testFunction(); // Output: I am a global variable