我想以与从文本字段输出值相同的方式输出复选框的值。由于复选框可以有多个输入,我为此使用了一个数组,但尝试循环遍历数组以获取值对我来说不起作用。尝试了 foreach($type as $item) 并在 HTML 中回显 $item ,就像我在 PHP 书中所说的那样,但这并没有奏效。我应该怎么做,代码应该在哪里?由于某种原因,我也无法在 HTML 中使用 PHP,我不确定这是为什么,或者它是否与 echo<<<_END 有关。帮助表示赞赏。
<?php // formtest.php
if (isset($_POST['game'])) $game = $_POST['game'];
else $game = "(Not entered)";
if (isset($_POST['genre'])) $genre = $_POST['genre'];
else $genre = "(Not entered)";
if (isset($_POST['type'])) $type = $_POST['type'];
else $type = "(Not entered)";
echo <<<_END
<html>
<head>
<title>Form Test</title>
</head>
<body>
Your game is: $game in the $genre genre and of the type<br />
<form method="post" action="formtest.php">
What is your game?
<input type="text" name="game" />
<br />
What is your genre?
<input type="text" name="genre" />
<br />
Type?
Retail <input type="checkbox" name="type[]" value="Retail" />
Downloadable <input type="checkbox" name="type[]" value="Downloadable" />
Free <input type="checkbox" name="type[]" value="Free" />
<br />
<input type="submit" />
</form>
</body>
</html>
_END;
?>