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>";
}
?>

原文地址:https://www.cnblogs.com/Toeasy/p/2384353.html