这篇文章主要介绍了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通过引用传递参数用法详解的详细内容,更多请关注Work网其它相关文章!

09-11 06:44