How does the usage of global variables in the PHP code impact its readability and maintainability?

Using global variables in PHP code can impact readability and maintainability negatively because it can make it difficult to track where and how the variable is being modified throughout the codebase. It can also lead to unexpected behavior if the variable is unintentionally changed in a different part of the code. To improve readability and maintainability, it's better to pass variables explicitly as function parameters or use object-oriented programming principles to encapsulate data.

// Avoid using global variables by passing variables as function parameters
function calculateTotal($items) {
    $total = 0;
    foreach ($items as $item) {
        $total += $item;
    }
    return $total;
}

$items = [10, 20, 30];
$total = calculateTotal($items);
echo "Total: $total";