服务器之家

服务器之家 > 正文

PHP通过引用传递参数用法分析

时间:2021-04-01 16:28     来源/作者:牛逼的霍啸林

本文实例讲述了PHP通过引用传递参数用法。分享给大家供大家参考,具体如下:

先看一个手册上的示例:

?
1
2
3
4
5
6
7
8
9
<?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.'
?>

输出:

?
1
This is a string, and something extra.

如果没有这个&符号,

?
1
2
3
4
5
6
7
8
9
<?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, '
?>

输出:

?
1
This is a string,

希望本文所述对大家PHP程序设计有所帮助。

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部