php中的函数有什么区别
按值传递参数- 传递变量的副本。
$b = 1;
function a($c) {
$c = 2; // modifying this doesn't change the value of $b, since $c a copy of $b; thus a separate entity.
}
a($b);
echo $b; // still outputs 1
通过引用传递参数?- 传递指向函数外部变量的指针。
$b = 1;
function a($c) {
$c = 2; // modifying this also changes the value of $b, the variable $c points to.
}
a($b);
echo $b; // outputs 2 now after calling a();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句