<html>
<head>
<title>An array example</title>
</head>
<body bgcolor=#CCCCCC>
<h1>An array example</h1>
<form>
<input name = name>
</form>
<?
$programmer[Python] ="Guido";
$programmer[Perl] ="Larry";
$programmer[PHP] ="Rasmus";
$programmer[Tcl] ="John";
$what = $_GET[name];
if ($what){
if($programmer[$what]){
print "$programmer[$what] wrote $what";
}
else{
print "$what ??? No such language.";
print "Known languages are:<ul>";
$thekeys = array_keys($programmer);
for ($l = 0; $l <count($thekeys); $l++){
print "<li>$thekeys[$l]";
}
print "</ul>";
}
}
else{
print "You need to enter a name of a language.";
}
?>
Another reading a file in as an array
<html>
<head>
<title>Roads</title>
</head>
<body bgcolor=#CCCC00>
<h1>An array from a file</h1>
<?
function walkit($item2, $key)
{
echo "<tr><td>$key<td> $item2\n";
}
$roads = file("../../data/roads.xyz");
print "The 1st 15 lines are<ol>";
for ($i=0; $i<15; $i++){
print "<li>$roads[$i]";
}
print "</ol>\n";
print "<hr>";
//Walk the file
print "<table border=1><th>Key<th>Item\n";
array_walk($roads,"walkit");
print "\n</table>";
?>
--
PeterJones - 07 Nov 2006