php获取$_POST同名参数数组

 今天写php的时候发现$_POST["arr"]无法获取参数arr的数组,记录一下。

 例如有以下表单需要提交:

  <input type="checkbox" name="arr" value="" />

  <input type="checkbox" name="arr" value="" />

  <input type="checkbox" name="arr" value="" />

  <input type="checkbox" name="arr" value="" />

 使用$_POST["arr"]只能获得最后选择的复选框的值,要获得全部选中的复选框的值需要把表单修改成下面:

  <input type="checkbox" name="arr[]" value="" />

  <input type="checkbox" name="arr[]" value="" />

  <input type="checkbox" name="arr[]" value="" />

  <input type="checkbox" name="arr[]" value="" />

这样就可以使用$_POST["arr"]获得全部选中的checkbox的值了。

原文地址:https://www.cnblogs.com/xiaonian/p/3151107.html