-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-forms-objects.php
More file actions
97 lines (76 loc) · 2.1 KB
/
basic-forms-objects.php
File metadata and controls
97 lines (76 loc) · 2.1 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- TEST FORM 1 -->
<!-- <form action="index.php" method="post">
<label>quantity: </label><br>
<input type="text" name="quantity">
<input type="submit" value="total">
</form> -->
<!-- TEST FORM 2 -->
<!-- <form action="index.php" method="post">
<label for="">x: </label>
<input type="text" name="x"><br>
<label for="">y: </label>
<input type="text" name="y"><br>
<label for="">z: </label>
<input type="text" name="z"><br>
<input type="submit" value="calculate!">
</form> -->
</body>
</html>
<?php
// ASSOCIATIVE ARRAYS <-------------
$capitals = array("USA" => "Washington DC",
"Japan" => "Kyoto",
"South Korea" => "Seoul",
"India" => "New Delhi");
// $capitals["USA"] = "new value";
// $capitals["new key"] = "new value";
// array_pop($capitals);
// array_shift($capitals);
// array_flip($capitals);
// array_reverse($capitals);
// ACCESSING KEYS <-------------
$keys = array_keys($capitals);
foreach($keys as $key){
echo"{$key}<br>";
}
// ACCCESSING VALUES <-------------
$values = array_values($capitals);
foreach($values as $value){
echo"{$value}<br>";
}
// ACCESSING KEYS AND VALUES <-------------
foreach($capitals as $key => $value){
echo"The capital of {$key} is {$value}<br>";
}
// TEST FORM 1 USES:
// $item = 'pizza';
// $price = 5.99;
// $quantity = $_POST["quantity"];
// $total = $quantity * $price;
// echo"You have ordered {$quantity} x {$item}s <br>";
// echo"Your total is: \${$total}";
// TEST FORM 2 USES:
// $x = $_POST["x"];
// $y = $_POST["y"];
// $total = null;
// $total = abs($x);
// $total = round($x);
// $total = floor($x);
// $total = ceil($x);
// $total = pow($x, $y);
// $total = sqrt($x);
// $total = max($x, $y, $z);
// $total = min($x, $y, $z);
// $total = pi();
// $total = rand(1, 21);
// echo $total;
?>