国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

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 />';

//你會(huì)發(fā)生$foo的值變?yōu)榱?0
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.


Continuing Learning
||
<?php $foo = 100; //注意:在$n前面加上了&符 function demo(&$n){ $n = 10; return $n + $n; } echo demo($foo).'<br />'; //你會(huì)發(fā)生$foo的值變?yōu)榱?0 echo $foo; ?>
submitReset Code