How can global variables be defined and accessed within PHP functions?

Global variables can be defined within PHP functions by using the `global` keyword followed by the variable name inside the function. This allows the function to access and modify the global variable. To access a global variable within a function, you can simply refer to it by its name. It's important to note that using global variables within functions can make the code harder to maintain and debug, so it's recommended to use them sparingly.

$globalVar = 10;

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

accessGlobalVariable(); // Output: 10