php - 更改参数值的 PHP 函数的名称是什么?

标签 php function parameters

<分区>

我注意到一些 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() 没有。

最佳答案

这里是一些关于php的这两个函数的文档。可以看到trim的参数是传值的,而sort的参数是传引用的。

值(value)和引用引用Pedro Lobito's answerhere

bool sort(array &array_arg [, int sort_flags])

string trim  ( string $str  [, string $charlist  ] )

关于php - 更改参数值的 PHP 函数的名称是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44050268/

相关文章:

PHP,Mysqli,如何绑定(bind)列中的参数并使用它们

php - 确定功能是否设置的正确方法

powershell - 如何确定当前管道步骤中绑定(bind)的参数?

asp.net - 查询字符串参数使我的应用程序面临风险?

php - 如何从 magento 1.5 类别中删除产品

php - fatal error : Call to a member function bind_param() on a non-object

php - 将括号留在 PHP if else 结构中会提高速度吗?

c - 在 C 中传递结构数组的元素

C++ - 关于函数模板实例化的规则

time - 当我输入 "%%time"时,这些参数在 jupyter notebook 中意味着什么?