FROM http://wangduowu.javaeye.com/blog/385935
在用到checkbox的时候发现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>
<input type="checkbox" name="weeks[]" id="weeks" value=2>
<input type="checkbox" name="weeks[]" id="weeks" value=3>
weeks后的中括号不可漏,否则用PHP获取的时候只能取到最后一个值。之后PHP就很好处理了,如下:
代码
//方法一:
$weeks = $_POST['weeks'];
for($i=0;$i<count($weeks);$i++)
echo $weeks[1]."<br>";
//方法二:
$array = $this->request->getParameter("weeks[]");
$str =implode(',',$array);
echo $str;
$weeks = $_POST['weeks'];
for($i=0;$i<count($weeks);$i++)
echo $weeks[1]."<br>";
//方法二:
$array = $this->request->getParameter("weeks[]");
$str =implode(',',$array);
echo $str;