How can functions be used in PHP to encapsulate and reuse code for variable manipulation across different files?

Functions in PHP can be used to encapsulate code that manipulates variables, making it easier to reuse the same code across different files. By defining a function that performs specific variable manipulations, you can call that function whenever you need to perform the same operation, without having to rewrite the code each time. This promotes code reusability and helps in maintaining a clean and organized codebase.

// Define a function to manipulate a variable
function manipulateVariable($var) {
    // Perform variable manipulation here
    $var = strtoupper($var);
    return $var;
}

// Call the function to manipulate a variable
$myVariable = "hello";
$manipulatedVariable = manipulateVariable($myVariable);
echo $manipulatedVariable; // Output: HELLO