How can functions be used to manipulate variables in PHP?
Functions can be used in PHP to manipulate variables by passing the variables as parameters to the function, performing the desired operations within the function, and then returning the modified value. This allows for reusable code and helps in organizing and simplifying complex operations on variables.
// Function to add 10 to a given number
function addTen($num) {
$result = $num + 10;
return $result;
}
// Example usage
$number = 5;
$newNumber = addTen($number);
echo $newNumber; // Output: 15