Home >Backend Development >PHP Tutorial >PHP从checkbox取值

PHP从checkbox取值

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:34:46849browse

 在用到checkbox的时候发现php只能取一个值,查了相关资料,原因如下:

Php代码

<input type="checkbox" name="weeks[]" id="weeks" value=1>  <input type="checkbox" name="weeks[]" id="weeks" value=2>  <input type="checkbox" name="weeks[]" id="weeks" value=3>   

weeks后的中括号不可漏,否则用PHP获取的时候只能取到最后一个值。之后PHP就很好处理了,如下:

Php代码 

方法一:  $weeks = $_POST['weeks'];  for($i=0;$i<count($weeks);$i++)  echo $weeks[$i]."<br>";     方法二:  $array = $this->request->getParameter("weeks[]");  $str =implode(',',$array);  echo $str;  

 

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
Previous article:php拾遗1Next article:Writing Silverlight applications in PHP