passing by reference与 passing by value的区别

fhjren 2002-03-05 06:26:35
如下一段程序:
<html>
<title>xxx.php</title>
<?
//first program
echo 'passing by reference:<br>';
function doo(&$bar)
{
$bar .='and something extra.';
}
$str='this is a string';
doo($str);
echo $str;
echo '<p>';
//secend function
echo'passing by value :';
function doo2($bar)
{.
$bar.='and something extra.';
}
$str='this is a string,';
doo2($str);
echo'<br>',$str;
doo2(&$str);
echo'<br>',$str;
?></html>
输出结果是:
passing by reference:
this is string,and something extra.

passing by value:
this is a string, and something extra
造成这样结果的诀窍是什么??doo2($str)与doo2(&$str)有什么不同?
...全文
155 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
SimonDW 2002-03-05
  • 打赏
  • 举报
回复
函数中对按值传送的变量的操作会影响该变量的值。
hqywork 2002-03-05
  • 打赏
  • 举报
回复
passing by reference:传递的只是变量的一个地址
passing by value:传递的是变量的复制品

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧