我在检索存储在关联数组中的信息时遇到问题。

时间:2013-12-10 22:26:59

标签: arrays associative

我是编程新手,也是编程课。我在关联数组中检索存储的信息时遇到问题。

<html>
<head>
<title>Lifespans</title>
<link rel ="stylesheet" type="text/css" href="sample.css" />
</head>

<body>
<h1>Lifespans</h1>
<?php
$animal = $_POST['animal'];

$lifespans = array('Mouse' => "4", => 'Queen Bee' => "5", 'Squirrel' => "20", 'Rattlesnake' => "22", => 'Pheasant' => "27", => 'Mallard Duck' => "29", => 'Bear' => "40", => 'Box Turtle' => "123");

$lifespan=$lifespans[$animal];

print("<p>The $animal has an average lifespan of $lifespan years.</p>");


?>
<a href="lifespans.html"> Try another animal..</a>
</body>
</html>

提前感谢您的帮助。

0 个答案:

没有答案