Home > Backend Development > PHP Tutorial > PHP获取表单所有复选框的值的方法_PHP

PHP获取表单所有复选框的值的方法_PHP

WBOY
Release: 2016-05-31 19:30:27
Original
987 people have browsed it

通常来说,php中总是只获取最后一个复选框的值,那么如何才能获取所有复选框的值?

解决办法如下:

form表单的部分代码如下:

<input type="checkbox" name="frm_tag[]" value="1">1
<input type="checkbox" name="frm_tag[]" value="2">2
<input type="checkbox" name="frm_tag[]" value="3">3
<input type="checkbox" name="frm_tag[]" value="4">4
<input type="checkbox" name="frm_tag[]" value="5">5

Copy after login

php处理POST传递过来数据的代码如下:

$str_tag = "";
$frm_tag = $_POST['frm_tag'];
for($i=0;$i<count($frm_tag);$i++){
  echo $frm_tag[$i]."<br>";
  if($i==0)
   $str_tag = $frm_tag[$i];
  else
   $str_tag = $str_tag.",".$frm_tag[$i];
}
echo $str_tag;
}

Copy after login

相信本文所述对大家深入掌握PHP程序设计有一定的借鉴价值。

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template