时间:2021-07-01 10:21:17 帮助过:11人阅读
//编写一个函数swap(),测试该函数的实参值无改变
function swap($a,$b) {
echo "进入swqp()函数前
\n";
\n";
echo "交换前:形参a=$a,形参b=$b
\n";
$c=$b;
$a=$b;
$b=$c;
echo "交换后:形参a=$a,形参b=$b
\n";
echo "退出swap()函数
}
$variablea=5;
$variableb=10;
echo "调用swap()函数前: ";
echo "实参a=$variablea,实参b=$variableb
\n";
swap($variablea,$variableb);
echo "调用swap()函数后: ";
echo "实参a=$variablea,实参b=$variableb
\n";
?>
代码如下:
//测试swap()函数实参的值改变
function swap1(&$a,&$b) {
echo "进入swap1()函数
\n";
\n";
echo "交换前: 形参a=$a,形参b=$b
\n";
$c=$b;
$a=$b;
$b=$c;
echo "交换后: 形参a=$a,形参b=$b
\n";
echo "退出swap()函数
}
$variablea=5;
$variableb=10;
echo "调用swap1()函数前: ";
echo "实参a=$variablea,实参b=$variableb
\n";
swap1($variablea,$variableb);
echo "调用swap1()函数后: ";
echo "实参a=$variablea,实参b=$variableb
\n";
?>
//上面的两个例子就是说明,求教了~~~