Home > php教程 > php手册 > php读取checkbox值几种方法

php读取checkbox值几种方法

WBOY
Release: 2016-06-13 10:03:28
Original
985 people have browsed it

php教程获取checkbox多选项值时必须以数组形式了,下如test[]再用php post获取就ko了,下面看代码。








注意上面input的name属性,各个属性内容都一样,而且都是test[],加上[]的原因在于让test的内容变成数组形式传递。
checktest.php的代码内容如下:

$str =implode(',',$_post['test']);

print_r($str);

12345

哦。下面看我一朋友写的。

php代码

  
  
   

 

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

php代码

方法一:  
$weeks = $_post['weeks'];  
for($i=0;$i echo $weeks[1]."
";   
  
方法二:  
$array = $this->request->getparameter("weeks[]");  
$str =implode(',',$array);  
echo $str;  

 

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