Professional Documents
Culture Documents
>>>
Day 2 Continuation PHP Array
3 4
5 6
1
10/11/2022
7 8
11 12
2
10/11/2022
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); <?php
asort($age); $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
?> krsort($age);
?>
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
ksort($age);
?>
17 18
3
10/11/2022
Superglobals
regardless of scope - and you can access them from
any function, class, or file without having to do anything
special.
20
PHP Global Variables - Superglobals PHP $GLOBALS anywhere in the PHP script (also from
within functions or methods).
4
10/11/2022
Most important elements that can go Most important elements that can go
inside $_SERVER inside $_SERVER
25 26
HP super global variable which is used to PHP super global variable which is used
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="fname"> Name: <input type="text" name="fname">
<input type="submit"> <input type="submit">
</form> </form>
<?php <?php
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field // collect value of input field
$name = $_REQUEST['fname']; $name = $_POST['fname'];
if (empty($name)) { if (empty($name)) {
echo "Name is empty"; echo "Name is empty";
} else { } else {
echo $name; echo $name;
} }
} }
?> ?>
</body> </body>
</html> </html>
27 28
</body>
</html>
<html>
<body>
<?php
echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
?>
</body>
</html>
29
5
10/11/2022
A Simple HTML Form To display the submitted data you could simply echo all the
variables. The "welcome.php" looks like this
<html>
<body>
<html>
<form action="welcome.php" method="post"> <body>
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br> Welcome <?php echo $_POST["name"]; ?><br>
<input type="submit"> Your email address is: <?php echo $_POST["email"]; ?>
</form>
</body>
</body> </html>
</html> 31 32
6
10/11/2022
Review
for
QUIZ 3
Get ¼ sheet of paper.