我正在向控制器发送一个POST阵列。数组看起来像这样:
Array
(
[event] => Array
(
[0] => Array
(
['publishStart'] => 2013-12-10
['eventStart'] => 2014-05-05
['eventEnd'] => 2014-05-10
['timeStart'] =>
['timeEnd'] =>
['location_id'] => 1
['id'] => 65774
)
这些块中有一些,即[事件] [1]。 [event] [2]等我试图在$ _POST ['event']上运行foreach循环,并且可以确认在每次迭代时,$ event包含以下内容:
Array
(
['publishStart'] => 2013-12-10
['eventStart'] => 2014-05-05
['eventEnd'] => 2014-05-10
['timeStart'] =>
['timeEnd'] =>
['location_id'] => 1
['id'] => 65774
)
现在,问题。您可以在上面的两个数组中看到一个名为“id”的键,其中包含相应的值。然而,以下代码返回一个“未定义索引”错误字符串:
foreach ($_POST['event'] as $event)
{
echo $event['id'];
exit();
}
我到底在做什么?
答案 0 :(得分:2)
您的数组索引似乎包含单引号。
尝试
echo $event["'id'"];