user1360250
user1360250

Reputation: 331

Access variables in stdClass object in PHP

I use the API of my CRM to receive contacts. Now, I want to access the email address of the contact:

$result = $api->findContacts($params);
print_r($result[0]->email);

returns ...

stdClass Object ( 
  [0] => [email protected] 
  [--primary] => [email protected] 
)

How can access the email address stored in [--primary] via PHP? I tried $result[0]->email->--primary etc, but does not work.

Thanks

Upvotes: 1

Views: 2334

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

Try this :

$primary = '--primary';

echo $result[0]->email->{$primary};

Upvotes: 1

Related Questions