[英]Multi-Dimensional array, returning wrong result
I have a multi-dimensional array (There is more than one item in "data" but i'm just showing one for this question): 我有一个多维数组(“数据”中有多个项目,但我只为这个问题显示一个):
Array
(
[data] => Array
(
[0] => Array
(
[to] => Array
(
[data] => Array
(
[0] => Array
(
[name] => fake name
[id] => 668071477234
)
[1] => Array
(
[name] => fake name
[id] => 1345556711
)
)
)
[updated_time] => 2012-12-24T23:46:26+0000
[id] => 327424994013537
)
)
)
I am trying to loop thru the array and determine if the id matches a variable sent from $_REQUEST, and if it does, I only want to return the "updated_time" value of the iteration. 我试图遍历数组并确定id是否匹配从$ _REQUEST发送的变量,如果匹配,我只想返回迭代的“ updated_time”值。
Here's what I have but the date is always wrong, and doesn't match the proper iteration: 这是我所拥有的,但是日期总是错误的,并且与正确的迭代不匹配:
foreach($userOutbox['data'] as $outbox){
foreach($outbox['to']['data'] as $user){
if($user['id'] == $_REQUEST['facebook_id']){
$last_message_date = $outbox['updated_time'];
}
}
}
It's late and my eyes and brain are not helping me. 已经晚了,我的眼睛和大脑没有帮助我。 Can anyone give me any direction?
谁能给我任何指示?
Here's the solution that worked for me, just added break 2;
这是对我有用的解决方案,只是添加了
break 2;
Thanks for your help: 谢谢你的帮助:
foreach($userOutbox['data'] as $outbox){
foreach($outbox['to']['data'] as $user){
if($user['id'] == $_REQUEST['facebook_id']){
$last_message_date = $outbox['updated_time'];
break 2;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.