<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

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2006-11-07 - PeterJones
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback