-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap.php
More file actions
38 lines (30 loc) · 736 Bytes
/
swap.php
File metadata and controls
38 lines (30 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html>
<head>
<title>Swap Two Numbers</title>
</head>
<body>
<h2>Swap Two Numbers Using Function</h2>
<form method="post">
Enter first number: <input type="number" name="a" required><br><br>
Enter second number: <input type="number" name="b" required><br><br>
<input type="submit" value="Swap">
</form>
<?php
function swapValues(&$x, &$y) {
$temp = $x;
$x = $y;
$y = $temp;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$a = $_POST['a'];
$b = $_POST['b'];
echo "<h3>Before Swapping:</h3>";
echo "a = $a, b = $b<br><br>";
swapValues($a, $b);
echo "<h3>After Swapping:</h3>";
echo "a = $a, b = $b";
}
?>
</body>
</html>