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] => mktest3@gmail.com
                                            [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>";
}
user3436467
  • 1,763
  • 1
  • 22
  • 35
  • 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. – user3436467 Feb 15 '16 at 02:55
  • 1
    `$array = json_decode( json_encode($response), TRUE );` ? – Darren Feb 15 '16 at 02:57
  • yep, appears i posted too early. I just found the same here: http://stackoverflow.com/questions/19495068/convert-stdclass-object-to-array-in-php – user3436467 Feb 15 '16 at 02:59

1 Answers1

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);
Community
  • 1
  • 1
user3436467
  • 1,763
  • 1
  • 22
  • 35