php checkbox 复选框

在给checkBox命名时,必须要加"[]" ,但是在接收时不能加"[]" 才能得到值!

例如:

html代码

<html>
<head>
<body>
<form action="result.php" method="POST">
<input type="checkbox" name="year[]" value="1">1 &nbsp;&nbsp;
<input type="checkbox" name="year[]" value="2">2 &nbsp;&nbsp;
<input type="checkbox" name="year[]" value="3">3 <br>
<input type="submit" name="btn_ok" value="ok">
</form>
</body>
</head>
</html>

 

result.php 代码:

<?php
foreach ($_POST['year'] as $item)
{
echo $item."<br>";
}
?>

posted @ 2012-03-07 22:23  toeasy  阅读(491)  评论(0编辑  收藏  举报