简单php获取复选框的值代码

前端之家收集整理的这篇文章主要介绍了简单php获取复选框的值代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

PHP中checkBox复选框我们以一般是使用数组形式来做的,这样在 PHP获取复选框值时我们会以数组形式存储的,所以只要遍历数组即可实现,代码如下:

  1. <html> 
  2. <head> 
  3. <title>获取复选框的值</title> 
  4. </head> 
  5. <body> 
  6. <form action="result.PHP" method="POST"
  7. <input type="checkBox" name="year[]" value="1">1 &nbsp;&nbsp; 
  8. <input type="checkBox" name="year[]" value="2">2 &nbsp;&nbsp; 
  9. <input type="checkBox" name="year[]" value="3">3 <br> 
  10. <input type="submit" value="提交" /> 
  11. </form> 
  12. </body> 
  13. </html> 

PHP代码,代码如下:

  1. <?PHP 
  2. foreach($_POST['year'as $item){ 
  3. echo $item."<br>"
  4. ?> 

猜你在找的PHP相关文章