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

PHP从checkbox取值

WBOY
Release: 2016-06-23 14:34:46
Original
817 people have browsed it

 在用到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>   
Copy after login

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