What potential pitfalls can arise when using global variables in PHP scripts?

Using global variables in PHP scripts can lead to issues with variable scope and potential conflicts with other parts of the code. To avoid these pitfalls, it is recommended to use function parameters or return values to pass data between functions instead of relying on global variables.

// Avoid using global variables by passing data as function parameters or return values

function calculateSum($num1, $num2) {
    return $num1 + $num2;
}

$number1 = 5;
$number2 = 10;

$result = calculateSum($number1, $number2);

echo "The sum of $number1 and $number2 is: $result";