Now that we have discussed arrays that have numeric indexes we need to
spend some time looking at arrays that use indexes that are strings.
These are often called associative arrays.
We are going to use a select box to list the names of some universities. A user should select one of the schools and press the button. The URL for the school will be displayed on another page. You should call the form page find_url.html.
<title>Find the URL</title>
<body bgcolor = "660066" text="cccccc">
<form action="find_url.php" method=post>
<table align = center>
<td><font size = 4 color=cccccc>Please select a school from the following list</font>
<td align = center><font size = 4 color=cccccc>
<td colspan = 2 align = center><input type = submit value="Find the URL">
You should call the processing script find_url.php.
<title>Finding a URL</title>
// initializing the array of URLs
// based on entry names
$urls = array(
"Michigan State" => "msu.edu",
"Purdue" => "purdue.edu",
"Quinnipiac" => "quinnipiac.edu",
"Rider" => "rider.edu",
"Syracuse" => "syracuse.edu",
"University Tennessee" => "utk.edu",
"Virginia Tech" => "vt.edu"
// displaying the URL bassed on finding the entry in the array
print "<center><h2>The URL for <b>$school_name</b> is = <b>$urls[$school_name]</b></h2></center>";
|Remember $school_name is determined by the value posted from the form control called school_name.|