Reputation: 1775
I am making an api call to Salesforce and print_r($response) returns the following results
QueryResult Object
(
[queryLocator] =>
[done] => 1
[records] => Array
(
[0] => stdClass Object
(
[Id] => 0018000001O5tRgAAJ
[Contacts] => stdClass Object
(
[done] => 1
[queryLocator] =>
[records] => Array
(
[0] => stdClass Object
(
[Id] => 0038000001yxYP3AAM
[Email] => [email protected]
[FirstName] => mary
[LastName] => kell
)
)
[size] => 1
)
[Name] => mktest3
)
)
I can use the following php script to pick out certain data from the first stdClass Object array but how can I do the same from the third? Basically I am trying to get the ID, Email, FirstName and LastName values for the contact.
foreach ($response->records as $record) {
$sObject = new SObject($record);
echo "<p>$sObject->Id</p>";
echo "<p>$sObject->Name</p>";
}
Upvotes: 1
Views: 2887
Reputation: 1775
Solution already available here: Convert stdClass object to array in PHP
The following converts the response to a standard array
$array = json_decode(json_encode($response), True);
Upvotes: 1