<分区>
我注意到一些 php 函数可以通过简单地调用函数来更改变量值,而其他函数则不能。例如,考虑 trim()
和 sort()
,它们都执行“action:”
//trim()
$string = " Test";
echo $string."<br>";
trim($string);
echo $string."<br>";
//each echo returns the same. trim() does nothing for the second echo
但是,使用 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
}
我知道使用两者的正确方法(做了 1000 次)。但是,这两个功能如何工作之间的区别的技术术语是什么? sort()
修改其变量(在某种程度上)但 trim()
没有。