stdClass对象和数组键值

时间:2013-01-29 14:53:57

标签: php arrays object stdclass

我有数组的以下对象并试图获取电子邮件的值。怎么办呢?

stdClass Object (
    [status] => stdClass Object ( 
        [info] => Unsubscribe List [code] => 200 
    ) 
    [data] => Array ( 
        [o1958147@rtrtr.com] => stdClass Object ( 
            [date] => 2013-01-28 08:09:19 
            [origin] => 
        ) 
        [phil.houston@granherne.com] => stdClass Object ( 
            [date] => 2013-01-28 08:35:59 
            [origin] => 
        ) 
    )    
) 

目前我可以使用以下foreach访问日期值。

foreach ($fnret->data as $msg)
{
    echo $msg->date;      // shows 2013-01-28 08:35:59
}

1 个答案:

答案 0 :(得分:5)

这个应该有效:

foreach ($fnret->data as $email => $msg) {
    // echo $msg->date;      // shows 2013-01-28 08:35:59
    echo $email;
}