<title>An array example</title>
<body bgcolor=#CCCCCC>
<h1>An array example</h1>
<input name = name>

$programmer[Python] ="Guido";
$programmer[Perl]   ="Larry";
$programmer[PHP]    ="Rasmus";
$programmer[Tcl]    ="John";

$what = $_GET[name];

if ($what){
   print "$programmer[$what] wrote $what";
   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>";
    print "You need to enter a name of a language.";

Another reading a file in as an array

<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";
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-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback