码迷,mamicode.com
首页 > 编程语言 > 详细

php获取checkbox数组的表单数据

时间:2017-03-30 13:21:13      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:ring   var_dump   ext   color   box   数据   动态   xhtml   UI   

提交表单的时候,对于checkbox多选框,name=“field[]”,此时php获取的数组为:从0开始的索引数组;如果name=“field[n]” 有数字n,那么php获取的name数组的索引为n,而不是从0开始的;

代码:

<html xmlns="http://www.jb51.net/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>php获取 checkbox复选框值的方法</title> 
</head> 
<body>
<form name="form1" method="post" action=""> 
<label> 
<input type="checkbox" name="checkbox[11]" value="复选一"> 
复选一 
</label> 
<label> 
<input type="checkbox" name="checkbox[22]" value="复选二"> 
</label> 
复选二 
<label> 
<input type="checkbox" name="checkbox[33]" value="复选三"> 
</label> 
复选三 
<label> 
<input type="checkbox" name="checkbox[44]" value="复选四"> 
</label> 
复选四 
<label> 
<input type="submit" name="Submit" value="提交"> 
</label> 
</form> 
</body> 
</html>

php:

if( $_POST ) 
{ 
    var_dump($_POST[‘checkbox‘]);
} 

打印结果为:

array(4) {
  [11]=>
  string(9) "复选一"
  [22]=>
  string(9) "复选二"
  [33]=>
  string(9) "复选三"
  [44]=>
  string(9) "复选四"
}
 

此时[]里面的数字,可以放一些动态数据,比如id,后台再处理

php获取checkbox数组的表单数据

标签:ring   var_dump   ext   color   box   数据   动态   xhtml   UI   

原文地址:http://www.cnblogs.com/feiying100/p/6645459.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!