How can global variables be effectively used to pass data between different methods in PHP?

Global variables can be used to pass data between different methods in PHP by declaring the variable outside of any function and then accessing and modifying it within the functions using the `global` keyword. This allows the variable to be shared and accessed across different functions without the need to pass it as a parameter each time.

$globalVar = "Initial Value";

function updateGlobalVar() {
    global $globalVar;
    $globalVar = "Updated Value";
}

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

updateGlobalVar();
displayGlobalVar(); // Output: Updated Value