Home  >  Article  >  Backend Development  >  PHP passing parameters by reference usage analysis

PHP passing parameters by reference usage analysis

黄舟
黄舟Original
2017-02-24 09:33:131121browse

The example in this article describes the usage of PHP passing parameters by reference. Share it with everyone for your reference, the details are as follows:

First look at an example in the manual:

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


Output:

This is a string, and something extra.


If there is no ampersand,

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


Output:

This is a string,



## The above is PHP by reference The content of passing parameter usage analysis. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn