这篇文章主要介绍了php通过引用传递参数用法,结合具体实例分析了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,
以上就是本文的全部内容,希望对大家的学习有所帮助。
相关推荐:
php安全配置记录与常见错误梳理详解
php实现获取当前日期及本周一是几月几号的方法
php中str_pad()函数用法详解
以上就是php通过引用传递参数用法详解的详细内容。