Home >Backend Development >PHP Tutorial >Detailed explanation of the usage of passing parameters by reference in PHP

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

墨辰丷
墨辰丷Original
2018-05-30 09:39:131833browse

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;
?>

Output:

This is a string, and something extra.

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;
?>

output:

This is a string,

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!

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