If you want to change GLOBAL variables, read then manual about functions:
Making arguments be passed by reference
By default, function arguments are passed by value (so that if you change the value of the argument within the function, it does not get changed outside of the
function). If you wish to allow a function to modify its arguments, you must pass them by reference.
If you want an argument to a function to always be passed by reference, you can prepend an ampersand (&) to the argument name in the function definition.
function add_some_extra(&$string) {
$string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str; // outputs 'This is a string, and something extra.'