Reputation: 1491
Below is my following return query from Salesforce. If i try to do $form_information[0]->Program_Type__c;
I get the following errors:
Cannot use object of type stdClass as array
Below is my following array which contains an object ?. My question is how can i extract the Program_type__c and Campus_ID__c from my object and save it into variables?
print_r($form_information);
Array
(
[totalSize] => 1
[done] => 1
[records] => Array
(
[0] => stdClass Object
(
[attributes] => stdClass Object
(
[type] => Program_Instance__c
[url] => /services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG
)
[Program_Type__c] => Field Science
[Program_Sub_type__c] =>
[Campus_ID__c] => a03i0000002DDBjAAO
)
)
)
array(3) {
["totalSize"]=>
int(1)
["done"]=>
bool(true)
["records"]=>
array(1) {
[0]=>
object(stdClass)#21 (4) {
["attributes"]=>
object(stdClass)#22 (2) {
["type"]=>
string(19) "Program_Instance__c"
["url"]=>
string(68) "/services/data/v22.0/sobjects/Program_Instance__c/a0Ji0000001EUk9EAG"
}
["Program_Type__c"]=>
string(13) "Field Science"
["Program_Sub_type__c"]=>
NULL
["Campus_ID__c"]=>
string(18) "a03i0000002DDBjAAO"
}
}
}
Upvotes: 0
Views: 268
Reputation: 72961
You are not traversing the object correctly.
I believe you are after something more like:
$form_information['records'][0]->Program_Type__c
However, I encourage you to read the introduction about PHP Arrays and Object Properties.
Upvotes: 5