I started studying PHP and I have a question about passing arguments by reference in a function.
I wrote this code:
<?php
$str = "ciao";
increment($str);
function increment(&$str){
strtoupper($str);
}
echo $str."\n";
?>
The result is "ciao" instead of "CIAO".
Why if I pass a variable, like $str, by reference to a function, the original variable dosen't come modify?. I though String $str is immutable in php (like Java) but it's not so. To modify the original value I should write
$str=strtoupper($str);
instead of
strtoupper($str);
So, in general, why if I pass an argument by reference in a function in PHP I have to save in the same varible the modify that i do in the function's body?
I hope to be clear, thanks
Luca