Detailed explanation of the usage of passing parameters by reference in PHP

墨辰丷
Release: 2023-03-28 12:32:01
Original
1798 people have browsed it

This article mainly introduces the usage of PHP passing parameters by reference, and combines specific examples to analyze the functions and operating techniques of using references to pass parameters in PHP function parameters. Friends in need can refer to the following

Read first An example from 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 Without the 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 the entire content of this article, I hope it will be helpful to everyone’s study.


Related recommendations:

php Detailed explanation of security configuration records and common errors

PHP implements the method of obtaining the current date and the day of the month this Monday is

str_pad() function in php Detailed explanation of usage

The above is the detailed content of Detailed explanation of the usage of passing parameters by reference in PHP. For more information, please follow other related articles on the PHP Chinese website!

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