-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.php
More file actions
29 lines (26 loc) · 759 Bytes
/
list.php
File metadata and controls
29 lines (26 loc) · 759 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
<!doctype html>
<html>
<head>
<title>A simple array</title>
</head>
<body>
<?php // list.php
/* This script receives a string in $_POST['words']. It then turns it into an array,
* sorts the array alphabetically, and reprints it.
*/
// Turn the incoming string into an array:
$words_array = explode(' ' , $_POST['words']);
if (is_array($words_array) && !empty($words_array)) {
/* If the array is indeed an array and is not empty, sort it, then display its
* individual elements using a foreach loop
*/
sort($words_array);
print "<p>An alphabetized version of your list is: <br />";
foreach ($words_array as $words) {
print("$words<br />");
}
print("</p>");
}
?>
</body>
</html>