Home >Backend Development >PHP Tutorial >Detailed explanation of the usage of passing parameters by reference in PHP
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 .= 'and something extra.'; } $str = 'This is a string, '; add_some_extra($str); echo $str; // outputs 'This is a string, and something extra.' ?>
Output:
This is a string, and something extra.
if Without the ampersand,
<?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, ' ?>
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!