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

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

WBOY
WBOYOriginal
2016-05-31 19:30:27911browse

通常来说,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

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

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

Statement:
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