Reference to parameters of php custom function
In the variable function, we have learned about variable references. Let’s review the knowledge:
<?php $a = 10; $b = &$a; $a = 100; echo $a.'---------'.$b; ?>
The appeal knowledge points are in the variable chapter. Variable references are described. It means that variables $a and $b point to the same storage location to store values.
The parameter reference of the function also has the same meaning, pointing the formal parameters and actual parameters to the same location. If the formal parameters change within the function body, the values of the actual parameters also change. Let's see through experiments:
<?php $foo = 100; //注意:在$n前面加上了&符 function demo(&$n){ $n = 10; return $n + $n; } echo demo($foo).'<br />'; //你会发生$foo的值变为了10 echo $foo; ?>
Through the above example, we found that the actual parameter is $foo. When calling the demo, let $foo and $n point to the same storage area. When $n's When the value changes. Then the value of $foo also changes.