Hasan Nawaz
Hasan Nawaz

Reputation: 121

stdClass objects and array key value

I have the following objects with arrays and trying to get the value of email. How can this be done?

stdClass Object (
    [status] => stdClass Object ( 
        [info] => Unsubscribe List [code] => 200 
    ) 
    [data] => Array ( 
        [[email protected]] => stdClass Object ( 
            [date] => 2013-01-28 08:09:19 
            [origin] => 
        ) 
        [[email protected]] => stdClass Object ( 
            [date] => 2013-01-28 08:35:59 
            [origin] => 
        ) 
    )    
) 

Currently i can access the date values with the following foreach.

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

Upvotes: 3

Views: 11554

Answers (1)

Sorin Trimbitas
Sorin Trimbitas

Reputation: 1497

This one should work :

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

Upvotes: 8

Related Questions