Home > Article > Backend Development > PHP passing parameters by reference usage analysis
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 .= '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 there is no 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,