2

我有一个多维数组(“数据”中有多个项目,但我只为这个问题显示一个):

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
                )
        )

)

我正在尝试遍历数组并确定 id 是否与从 $_REQUEST 发送的变量匹配,如果匹配,我只想返回迭代的“updated_time”值。

这是我所拥有的,但日期总是错误的,并且与正确的迭代不匹配:

    foreach($userOutbox['data'] as $outbox){
        foreach($outbox['to']['data'] as $user){
            if($user['id'] == $_REQUEST['facebook_id']){                                           

                      $last_message_date = $outbox['updated_time'];
            }
        }
    }

已经很晚了,我的眼睛和大脑都没有帮助我。任何人都可以给我任何方向吗?

4

1 回答 1

0

这是对我有用的解决方案,刚刚添加break 2; 感谢您的帮助:

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;
        }
    }
}
于 2013-01-12T20:28:41.033 回答