What steps can be taken to ensure that PHP functions do not rely on global variables for better code quality?

Global variables can lead to code that is difficult to test, maintain, and reason about. To avoid relying on global variables in PHP functions, you can pass necessary values as parameters to the function instead. This makes the function more self-contained and easier to understand.

// Avoid using global variables in PHP functions by passing necessary values as parameters
function calculateTotal($quantity, $price) {
    return $quantity * $price;
}

$quantity = 10;
$price = 5;
$total = calculateTotal($quantity, $price);
echo "Total: $total";