简体   繁体   中英

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] => ckauwan_t@tsp-t.com 
  [--primary] => ckauwan_t@tsp-t.com 
)

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

Thanks

Try this :

$primary = '--primary';

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM