为什么$ _POST返回多个数组

时间:2012-05-24 18:07:21

标签: multidimensional-array

我有以下HTML表单

<form id="form2" name="form2" method="post" action="process.php">
<table width="271" border="1">
<tr>
  <td width="5"><input name="txtIdone2" type="text" id="txtIdone2" value="Richard" /></td>
  <td width="250">
  <label for="txtIdone"></label>
  <input name="txtIdone" type="text" id="txtIdone" value="Hopes" />
</td>
</tr>
<tr>
  <td><input name="txtIdone3" type="text" id="txtIdone3" value="Testing" /></td>
  <td><input name="txtIdone4" type="text" id="txtIdone4" value="this" /></td>
</tr>
<tr>
  <td><input name="txtIdone5" type="text" id="txtIdone5" value="it" /></td>
  <td><input name="txtIdone6" type="text" id="txtIdone6" value="works" /></td>
</tr>
<tr>
  <td colspan="2"><input type="submit" name="btnTest" id="btnTest" value="Submit" />
    </td>
</tr>
</table>
</form>

提交具有以下代码的process.php:

    $data = array($_POST);
print_r ($data);

简单。但是,我没有返回常规数组,而是收到了一个多数组。这是一个例子:

  

Array
(
    [0] => Array
        (
            [txtIdone2] => Richard
            [txtIdone] => Hopes
            [txtIdone3] => Testing
            [txtIdone4] => this
            [txtIdone5] => it
            [txtIdone6] => works
        )

)

我只想要一个常规数组返回。我做错了什么?

感谢。

1 个答案:

答案 0 :(得分:1)

$_POSTalready an array

通过执行$data = array($_POST);,您将使数组成为多维的。

尝试简单地做:

print_r($_POST);