I’m dealing with data retrieved from HubSpot’s API and I need assistance in accessing particular values from the JSON response. After decoding, I’m left with a complicated nested structure like this:
stdClass Object(
[contactId] => 45
[createdAt] => 1512345678901
[portalId] => YYYYY
[contactData] => stdClass Object
(
[email] => stdClass Object
(
[content] => [email protected]
)
[company] => stdClass Object
(
[content] => Sample Corp
)
)
[userProfiles] => Array
(
[0] => stdClass Object
(
[profileId] => 45
[contacts] => Array
(
[0] => stdClass Object
(
[category] => EMAIL
[content] => [email protected]
[created] => 1512345678901
)
[1] => stdClass Object
(
[category] => VISITOR_ID
[content] => abc123-def456-ghi789
[created] => 1512345678902
)
)
)
)
)
I aim to retrieve the email address located in the userProfiles section. When I try this code:
echo $response->contacts[0]->user-profiles;
It simply returns 0. Then, I attempt:
echo $response->contacts[0]->user-profiles[0];
But I encounter a syntax error. What is the correct way to access nested properties that have hyphens in PHP? I need to navigate to userProfiles[0]->contacts[0]->content to extract the email value.