<php
$toppings = filter_input(INPUT_POST, 'top',
FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY);
if ($toppings !== NULL) {
$top1 = $toppings[0]; // $top1 is pep
$top2 = $toppings[1]; // $top2 is olv
$top3 = $toppings[2]; // $top3 is not set – throws an error
}
?>
<php
$toppings = filter_input(INPUT_POST, 'top',
FILTER_SANITIZE_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY);
if ($toppings !== NULL) {
echo("<p>");
foreach($toppings as $key => $value) {
echo("$key = $value<br />\n");
}
echo("</p>\n");
} else {
echo("No toppings selected.</p>\n");
}
?>