How can passing variables through function parameters affect PHP script execution?
Passing variables through function parameters in PHP can affect script execution by allowing the function to manipulate the values of those variables directly. This can lead to unintended side effects or unexpected behavior if not handled carefully. To avoid this, it's recommended to pass variables by value or use return statements to handle the output of functions instead of directly modifying variables passed by reference.
// Example of passing variables by value
function multiplyByTwo($num) {
return $num * 2;
}
$number = 5;
$result = multiplyByTwo($number);
echo $result; // Output: 10