PHP will issue a warning when the number of actual parameters Before entering the swqp() function< ;br>n"; Enter swap1() function
When writing functions in PHP, generally when calling a function, the changed values are the formal parameters rather than the actual parameters. However, if an address character is added to the formal parameters, the value of the actual parameters will be changed. Why?
Please see the example below:
//Write a function swap() and test that the actual parameter values of the function have not changed
function swap($a,$b) {
echo "
echo "Before exchange: formal parameter a=$a, formal parameter b=$b
n";
$c=$b;
$a=$b ;
$b=$c;
echo "After exchange: formal parameter a=$a, formal parameter b=$b
n";
echo "Exit the swap() function
n";
}
$variablea=5;
$variableb=10;
echo "Before calling the swap() function: ";
echo "actual parameters a=$variablea,actual parameter b=$variableb
n";
swap($variablea,$variableb);
echo "After calling the swap() function: ";
echo "actual parameter a=$variablea,actual parameter b=$variableb
n";
?>
//Test the value change of the swap() function parameter
function swap1(&$a,&$b) {
echo "
n";
echo "Before exchange: formal parameter a=$a, formal parameter b=$b
n";
$c=$ b;
$a=$b;
$b=$c;
echo "After exchange: formal parameter a=$a, formal parameter b=$b
n";
echo "Exit the swap() function
}
$variablea=5;
$variableb=10;
echo "Call swap1( ) before function: ";
echo "actual parameter a=$variablea,actual parameter b=$variableb
n";
swap1($variablea,$variableb);
echo "call swap1( ) function: ";
echo "actual parameter a=$variablea, actual parameter b=$variableb
n";
?>
//The above two An example is just to illustrate, please give me some advice~~~