How does PHP handle variable scope within functions?

In PHP, variables declared inside a function have local scope by default, meaning they can only be accessed within that function. To access variables from outside the function, you can use the global keyword to declare them as global variables within the function. Alternatively, you can pass variables as parameters to the function.

$globalVar = 10;

function myFunction() {
    global $globalVar;
    echo $globalVar; // Output: 10
}

myFunction();