php 按引用传递的使用
测试1
function add($a)
{
$a+=1;
echo $a."<hr>";
}
$a = 1;
add($a);
echo $a
输出:
1
1
测试2
function add($a)
{
$a+=1;
echo $a."<hr>";
}
$a = 1;
add(& $a);
echo $a
输出虽然达到了效果,但是会报错
Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of add(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in path on line 8
2
2
测试3
function add(& $a)
{
$a+=1;
echo $a."<hr>";
}
$a = 1;
add($a);
echo $a
结果
2
2
这个才是正确的
posted on 2012-02-13 22:38 cn三少<script></script> 阅读(185) 评论(0) 编辑 收藏 举报