How do I read the variable of an array within an object

Scriber
Scriber used Ask the Experts™
on
I am using php imap and I want to (for the time being) extract the from address in the form "joe.bloggs@domain.co.uk" from the $headers object below.

print_r ($headers);

//Ouputs

stdClass Object
(
    [from] => Array
        (
            [0] => stdClass Object
                (
                    [personal] => Joe Bloggs
                    [mailbox] => joe.bloggs
                    [host] => domain.co.uk
                )

        )
)

Open in new window


Any help would be greatly appreciated.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
This should do the trick:

$from=$headers->from[0]->mailbox.'@'.$headers->from[0]->host;
echo $from;

Author

Commented:
Thank you! I actually just managed to find the answer on stackoverflow but you beat me to it :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial