First off, for various reasons, I'm stuck using NuSOAP with this particular client. But secondly what I've found is that when I query the Lead table, I get a different dimension array result when there is one record versus more than one. This makes it difficult to know how to run my nested foreach loops.
For example, if I have a single record, the var_dump of my array looks like this:array(4) { ["type"]=> string(4) "Lead" ["id"]=> string(18) "00Q7000000WDBaXEAX" ["values"]=> array(4) { ["FirstName"]=> string(34) "Chuck another test record to leave" ["LastName"]=> string(31) "Wyatt leave for nurture testing" ["Email"]=> string(30) "nurturetest@wordimpressive.com" ["VFS_Trial_Begins__c"]=> string(10) "2010-09-05" } ["fieldsToNull"]=> NULL }
On the other hand if I have more than one, I've got this, everything is wrapped around yet an additional array:
array(2) { [0]=> array(4) { ["type"]=> string(4) "Lead" ["id"]=> string(18) "00Q7000000WDBaXEAX" ["values"]=> array(4) { ["FirstName"]=> string(34) "Chuck another test record to leave" ["LastName"]=> string(31) "Wyatt leave for nurture testing" ["Email"]=> string(30) "nurturetest@wordimpressive.com" ["VFS_Trial_Begins__c"]=> string(10) "2010-09-05" } ["fieldsToNull"]=> NULL } [1]=> array(4) { ["type"]=> string(4) "Lead" ["id"]=> string(18) "00Q7000000V6R2jEAF" ["values"]=> array(4) { ["FirstName"]=> string(13) "vreports test" ["LastName"]=> string(13) "vreports test" ["Email"]=> string(28) "vreports@howfishoilworks.com" ["VFS_Trial_Begins__c"]=> string(10) "2010-09-05" } ["fieldsToNull"]=> NULL } }
What's the best way to handle? An example of the array looping code I've been working with is below. But of course it fails in the event there is only one record (!).
Thanks!!
-Chuck
$response = obj2array($queryResult[records]);
$arr = array($response);
foreach ($arr as $key=>$temp) {
foreach ($temp as $secondkey=>$temp2) {
echo "got this: $secondkey = $temp2","<br><br>";
// we transfer to variables we can use for mailing and logging:
foreach ($temp2 as $thirdkey=>$temp3) {
if ($thirdkey == 'id') { $sfid = $temp3; }
if ($thirdkey == 'type') { $recordtype= $temp3; }
echo "$sfid this one:" . "$thirdkey = $temp3","<br><br>";
foreach ($temp3 as $fourthkey =>$temp4) {
// we transfer to variables we can use for mailing and logging:
if ($fourthkey == 'FirstName') { $firstname = $temp4; }
if ($fourthkey == 'LastName') { $lastname = $temp4; }
if ($fourthkey == 'Email') { $email = $temp4; }
if ($fourthkey == 'VFS_Trial_Begins__c') { $trialbegins = $temp4;
}
}
}
Bookmarks