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

901次阅读
没有评论

共计 484 个字符,预计需要花费 2 分钟才能阅读完成。

实例介绍 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,

正文完
 0