Use array to store multiple values in PHP
Description
The following code shows how to use array to store multiple values.
Example
<html>// w w w . j a v a 2 s .c o m
<body>
<?php
$food = $_GET["food"];
if (!empty($food)){
echo "The foods selected are: <strong>";
foreach($food as $foodstuff){
echo '<br />'.htmlentities($foodstuff);
}
echo "</strong>.";
}
else {
echo ('
<form action="'. htmlentities($_SERVER["PHP_SELF"]).'" method="GET">
<fieldset>
<label>
Italian
<input type="checkbox" name="food[]" value="Italian" />
</label>
<label>
Mexican
<input type="checkbox" name="food[]" value="Mexican" />
</label>
<label>
Chinese
<input type="checkbox" name="food[]" value="Chinese" checked="checked" />
</label>
</fieldset>
<input type="submit" value="Go!" />
</form> ');
}
?>
</body>
</html>