/    Sign up×
Community /Pin to ProfileBookmark

calling a property from an object

Here is a test object

[CODE]stdClass Object (
[date] => Tue, 15 May 2012 13:41:22 +0800
[Date] => Tue, 15 May 2012 13:41:22 +0800
[subject] => Smart & Zone
[Subject] => Smart & Zone
[message_id] => <[email protected]>
[toaddress] => WOO WOO
[to] => Array (
[0] => stdClass Object (
[personal] => WOO WOO
[mailbox] => WOO WOO
[host] => example.com.au
) )
[fromaddress] => WOO WOO
[from] => Array (
[0] => stdClass Object (
[personal] => WOO WOO
[mailbox] => WOO WOO
[host] => example.com.au
)
)
[Recent] =>
[Unseen] =>
[Flagged] =>
[Answered] =>
[Deleted] =>
[Draft] =>
[Msgno] => 1
[MailDate] => 15-May-2012 13:41:23 +0800
[Size] => 7046
[udate] => 1337060483
)
[/CODE]

I wanted to get the host from the from property.
Here is what I have for calling.

[CODE]($emailCountData->from->0->host == “example.com.au”[/CODE]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ericatekkaauthorMay 17.2012 — also tried

$emailCountData->from[0]->host
Copy linkTweet thisAlerts:
@NogDogMay 18.2012 — also tried

$emailCountData->from[0]->host[/QUOTE]


Looks like that should work:
[code=php]
<?php
$foo = new stdClass();
$foo->from = array();
$foo->from[0] = new stdClass();
$foo->from[0]->host = 'example.com';
echo "<p>Host name: " . $foo->from[0]->host . "</p>n";
echo "<pre>".print_r($foo,1)."</pre>";
[/code]

Output:
<i>
</i>Host name: example.com

stdClass Object
(
[from] =&gt; Array
(
[0] =&gt; stdClass Object
(
[host] =&gt; example.com
)

<i> </i> )

)
Copy linkTweet thisAlerts:
@NogDogMay 18.2012 — PS: Note that I'm running PHP 5.4 in case that has any bearing on things.
Copy linkTweet thisAlerts:
@ericatekkaauthorMay 21.2012 — No sorry I just didn't finish the post correctly.

Got it working now. Thanks Nog.
×

Success!

Help @ericatekka spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...