【发布时间】:2018-04-04 12:22:30
【问题描述】:
按照这个post,我在一个表单中创建了这个html:
...
<input type="text" name="setValues[cardExpiration]" id="card_expiry" class="input-small" value="1222">
<input type="text" name="setValues[ipAddress]" id="ip" value="24.37.246.194">
...
提交表单后,在$_POST 数组中,我看到了这个多维数组,正如预期的那样:
当我尝试检索该值时,发生了一些事情:
$email = (isset($_POST["setValues"])?$_POST["setValues"]["email"]:FALSE);//Gives NULL
$email = (isset($_POST["setValues"])?$_POST["setValues"]["'email'"]:FALSE);//Gives the email filled in the form.
这里的重点是数组键中的'键'单引号。它是关键的一部分。
这就是为什么$_POST["setValues"]["'email'"] 有效而$_POST["setValues"]["email"] 无效。
那么我应该怎么做才能得到键内没有引号的数组呢?如何在输入属性中正确设置?
这是 var_dump():
echo '<pre>';
var_dump($_POST);
echo '</pre>';
【问题讨论】:
-
$_POST["setValues"]["'email'"]不起作用,$_POST["setValues"]["email"]起作用,正如预期的那样 - 请参阅下面的答案。
标签: php arrays post input attributes