What is the best practice for defining variables in PHP to be used in multiple functions and updated values?

When defining variables in PHP to be used in multiple functions and updated values, it is best practice to use global variables or pass variables by reference to functions. This ensures that the variables are accessible and can be modified across different functions without the need to constantly pass them as function arguments.

<?php

// Define a global variable
$globalVar = 5;

function updateGlobalVar() {
    // Access the global variable within the function
    global $globalVar;
    
    // Update the global variable
    $globalVar += 10;
}

// Call the function to update the global variable
updateGlobalVar();

// Print the updated global variable
echo $globalVar; // Output: 15

?>