临时变量法
echo "\n---临时变量法---\n";
$num1 = 3;
$num2 = 6;
echo "交换前:\n", '$num1 = ', $num1, "\n", '$num2 = ', $num2, "\n";
$tmp = $num1;
$num1 = $num2;
$num2 = $tmp;
echo "交换后:\n", '$num1 = ', $num1, "\n", '$num2 = ', $num2, "\n";
/*
---临时变量法---
交换前:
$num1 = 3
$num2 = 6
交换后:
$num1 = 6
$num2 = 3
*/
加减法
echo "\n---加减法---\n";
$num1 = 3;
$num2 = 6;
echo "交换前:\n", '$num1 = ', $num1, "\n", '$num2 = ', $num2, "\n";
$num1 = $num1 + $num2;
$num2 = $num1 - $num2;
$num1 = $num1 - $num2;
echo "交换后:\n", '$num1 = ', $num1, "\n", '$num2 = ', $num2, "\n";
/*
---加减法---
交换前:
$num1 = 3
$num2 = 6
交换后:
$num1 = 6
$num2 = 3
*/
异或法
echo "\n---异或法---\n";
$num1 = 3;
$num2 = 6;
echo "交换前:\n", '$num1 = ', $num1, "\n", '$num2 = ', $num2, "\n";
$num1 = $num1 ^ $num2;
$num2 = $num1 ^ $num2;
$num1 = $num1 ^ $num2;
echo "交换后:\n", '$num1 = ', $num1, "\n", '$num2 = ', $num2, "\n";
/*
---异或法---
交换前:
$num1 = 3
$num2 = 6
交换后:
$num1 = 6
$num2 = 3
*/
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。