How can the function textreplacesave be modified to allow for call-by-reference instead of call-by-value in PHP?

In PHP, variables are passed by value by default, which means that changes made to the parameter within a function do not affect the original variable outside the function. To allow for call-by-reference in PHP, you can use the `&` symbol before the parameter in the function definition. This tells PHP to pass the variable by reference, allowing changes made within the function to affect the original variable.

function textreplacesave(&$text, $search, $replace) {
    $text = str_replace($search, $replace, $text);
    file_put_contents('output.txt', $text);
}

$text = "Hello, world!";
$search = "world";
$replace = "PHP";
textreplacesave($text, $search, $replace);

echo $text; // Output: Hello, PHP!