Home > php教程 > php手册 > 简单php获取复选框的值代码

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

WBOY
Release: 2016-05-25 16:49:43
Original
955 people have browsed it

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

<html> 
<head> 
<title>获取复选框的值</title> 
</head> 
<body> 
<form action="result.php" method="POST"> 
<input type="checkbox" name="year[]" value="1">1    
<input type="checkbox" name="year[]" value="2">2    
<input type="checkbox" name="year[]" value="3">3 <br> 
<input type="submit" value="提交" /> 
</form> 
</body> 
</html>
Copy after login

php代码,代码如下:

<?php 
foreach($_POST[&#39;year&#39;] as $item){ 
    echo $item."<br>"; 
}
Copy after login

               
               

本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template