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

PHP passing parameters by reference usage analysis

黄舟
Release: 2023-03-06 06:14:01
Original
1138 people have browsed it

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;
?>
Copy after login


Output:

This is a string, and something extra.
Copy after login


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;
?>
Copy after login


Output:

This is a string,
Copy after login



## 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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template