Day pass PHP function reference value


<?php
function f1($p1,&$p2){
$p1++;
$p2++;
$result= $p1+ $p2;
return $result;
}
$v1=10;
$v2=20;
$s = f1($v1,$v2);
echo "<br>s=$s,v1=$v1,v2=$v2";
// <br>s=32,v1=10,v2=21
?>
 

 

Function execution principle (Key / difficulty)

Program always runs in a "memory."

Spatial location where the program begins execution, you can call the "main operational space."

In fact, usually a function outside those programs, are running in the main space.

Then, run the function, it is relatively independent of - every function of every call, it is run in a separate own space.

As follows:


prompt:

At time into the space functions from the main space, "real parameter according to" when the function call will first assignment (by value) to the "formal parameters"

Then, we began the implementation of the internal function statement!

 

 

 

Function parameters (focus)

Parameter (formal parameter)

Time is defined functions, variable names given in parentheses after the function name.

Parameter, internal use only function - i.e., the use of variable current limited to internal functions.

Variable parameter is the essence!

 

 

 

Arguments (actual parameters)

It is to call a function when the data given in parentheses after the function name value.

The essence of the argument is the data!

 

 

 

Function parameters by value

meaning:

Argument value of the variable parameter passed in what manner.

Description:

Provided that: the argument is the case of a variable.

So in fact we discussed here: the issue by value of two variables.

By default, the value is passed.

 

Can use the "&" symbol is set as the reference transmission, the following form:

function  f1( $p1, &$p2, .... ){  

。。。。。

}

In this case, within a function to change the value of the parameter variable corresponding to the value of the argument variables (outside function) is also changed.

 
--------------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/10961089.html