What are the potential issues with using global variables in PHP code?

Using global variables in PHP code can lead to potential issues such as variable scope conflicts, making the code harder to maintain and debug. To solve this issue, it is recommended to use functions or classes to encapsulate variables and pass them as parameters instead of relying on global variables.

// Avoid using global variables by encapsulating variables within functions or classes

function calculateTotal($price, $quantity) {
    $total = $price * $quantity;
    return $total;
}

$price = 10;
$quantity = 5;
$total = calculateTotal($price, $quantity);

echo "Total: $total";