function myfunction($num,$a,$b,$c) { echo "a".$a; echo "-b".$b; echo "-c".$c; echo "
"; $b+=2; $c+=3; $a+=1; echo "a".$a; echo "-b".$b; echo "-c".$c; echo "-num".$num; } myfunction(100,1,2,3); 运行结果:
A1-b2-c3
a2-b4-c6-num100
My inference is that the function is a one by one-corresponding relationship between the run-time formal parameter and the argument
But when I only want to pass $num $a $c These three parameters do not want to pass $b should be if the argument
MyFunction (100,1,3);
Operation Result:
A1-b3-c
a2-b5-c3-num100
I'm actually trying to make $a =1 $c =3 don't $b.
Reply content:
function myfunction($num,$a,$b,$c) { echo "a".$a; echo "-b".$b; echo "-c".$c; echo "
"; $b+=2; $c+=3; $a+=1; echo "a".$a; echo "-b".$b; echo "-c".$c; echo "-num".$num; } myfunction(100,1,2,3); 运行结果:
A1-b2-c3
a2-b4-c6-num100
My inference is that the function is a one by one-corresponding relationship between the run-time formal parameter and the argument
But when I only want to pass $num $a $c These three parameters do not want to pass $b should be if the argument
MyFunction (100,1,3);
Operation Result:
A1-b3-c
a2-b5-c3-num100
I'm actually trying to make $a =1 $c =3 don't $b.
The function parameter is one by one corresponding, if you do not want to pass a parameter can set the default value
function myfunction($num=0,$a=0,$b=0,$c=0){...}//调用函数位置要留出来myfunction(100,,1,2);
The title of the main summary of the right, 实参和形参就是一一对应的关系
.
If you have three formal parameters, but you just want to pass the first and third arguments, corresponding to the first and third of the formal parameters, then use the method upstairs;
There is another, is generally, the non-commonly used formal parameters to put the last, and give that parameter a default value ( This value is based on business logic ), so you pass the parameters only pass the first few parameters you want to pass, you can ignore the following.
When the function is defined, the corresponding parameter is the formal parameter, which corresponds to you here is-function myfunction ($num, $a, $b, $c) {}.
When the function is called, the corresponding arguments are, arguments, corresponding to you here is-myfunction (100,1,2,3).
must correspond to each other.
When you write a function, how many parameters are defined, how many parameters will be written when the call is made, and the principle is the same as the queue name, you empty one, if you do not leave a position to explain is vacant, it will let the back of the people on top, resulting in the final position vacancy