1

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>";
}
3
  • I would also be interested if the whole response can be converted to an array, that might make it easier for me to retrieve the data. Commented Feb 15, 2016 at 2:55
  • 1
    $array = json_decode( json_encode($response), TRUE ); ? Commented Feb 15, 2016 at 2:57
  • yep, appears i posted too early. I just found the same here: stackoverflow.com/questions/19495068/… Commented Feb 15, 2016 at 2:59

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

super solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.