You need to sign in to do that
Don't have an account?
אביב קסוטו
How to extract key in sObject array using value of a field in php
i have an sObject array that has the following objects:
[0]=> object(SObject)#1 (2) { ["type"]=> string(9) "Course__c" ["fields"]=> array(1) { ["Id__c"]=> string(3) "111" } } [1]=> object(SObject)#2 (2) { ["type"]=> string(9) "Course__c" ["fields"]=> array(1) { ["Id__c"]=> string(3) "222" }
Now, i have a string array of ids (for this example lets say it contains only "111"). What would be the best way to iterate over the object array and exatract the key of the object where id__c = "111"? in this example it would return "0".
Any help would be greatly appreciated.
All Answers
Use array_filter like this:
- For the Sobject version, replace $element['fields']['Id_c'] with $element->fields['Id_c']
- Also if you would like to pass a variable inside the callback function use:
Please mark this as solved if it's resolved so that others can benefit out of it if they are encountering a similar issue.Best Regards,
Nagendra.