I noticed that some php functions have the power to change a variables value by simply calling the function and others do not. For instance, consider trim()
and sort()
which both perform an "action:"
//trim()
$string = " Test";
echo $string."<br>";
trim($string);
echo $string."<br>";
//each echo returns the same. trim() does nothing for the second echo
However, with sort():
//sort()
$fruits = ['squash','apple','kiwi'];
foreach($fruits as $fruit){
echo $fruit."<br>";
//returns array in original order
}
sort($fruits);
foreach($fruits as $fruit){
echo $fruit."<br>";
//returns sorted array
}
I know the correct way to use both (done it a 1000 times). But what is the technical term for the difference between how these two functions work? sort()
modifies its' variable (to some extent) but trim()
does not.