3

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
}
1
  • foreach ($array as $key => $value) is the answer. The $key holds value of what is in [] brackets. [key] => value Commented Mar 1, 2013 at 10:07

1 Answer 1

8

This one should work :

foreach ($fnret->data as $email => $msg) {
    // echo $msg->date;      // shows 2013-01-28 08:35:59
    echo $email;
}
Sign up to request clarification or add additional context in comments.

1 Comment

To clarify it a bit so it does not look like magic. It's simple foreach ($array as $key => $value) statement. Meaning, this would be the input $array = Array ("key" => "value", 0 => 42, "p1" => "another");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.