实例介绍PHP中使用&符号引用传参

 ll2l   2019-04-03 22:11   507 人阅读  0 条评论

实例介绍PHP中使用&符号引用传参,先上一个实例来看一下如何引用传递参数


<?php
function add_some_extra(&$string) // 引入变量,使用同一个存储地址
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, and something extra.'
?>


输出:
This is a string, and something extra.

如果没有这个&符号,

<?php
function add_some_extra($string) 
{
    $string .= 'and something extra.';
}
$str = 'This is a string, ';
add_some_extra($str);
echo $str;    // outputs 'This is a string, '
?>


输出:
This is a string,



本文地址:http://www.hnzzwz.com/blog/post/72.html
版权声明:本文为原创文章,版权归 ll2l 所有,欢迎分享本文,转载请保留出处!

 发表评论


表情

还没有留言,还不快点抢沙发?