I am having trouble retrieving information stored in an associative array.

44 views Asked by At

I am very new to programming, and am in a programming class. I have having trouble retrieving stored information in my associative array.

<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>

thank you in advance for any help.

0

There are 0 answers