what is passing parameters by reference php code example
Example 1: php pass by reference
<?php
function appendToString(&$string)
{
$string .= 'Cool Im appended';
}
$str = 'I am a start and - ';
appendToString($str);
echo $str;
?>
Example 2: php & before variable
It passes a reference to the variable so when any variable assigned the reference
is edited, the original variable is changed. They are really useful when making
functions which update an existing variable. Instead of hard coding which variable
is updated, you can simply pass a reference to the function instead.
Example
<?php
$number = 3;
$pointer = &$number;
echo $number."<br/>";
$pointer = 24;
echo $number;
?>