All,
Been trying to fix this issue for some time without any progress… Any feedback is more than welcome.
We are using simple auth based on users caller id and YoB – if he has unique YoB, he can access the service, if there’s another user under that caller id with the same YoB: he gets a message that additional info is required.
The goal of a function is to return a record of a matching user – at the moment, it returns always the last record.
PHP Code:
// $response -> XML record with firstName, lastName and dob (dd/mm/yyyy)
// $yob -> YoB user has entered for authentication
function parseResponseYOB($response, $yob)
{
$duplicates = 0; // If there are users with same YoB, display message that additional info is required
if(empty($response->CallerMembers->CallerMemberDetails->dob))
{
$iterateArr = $response->CallerMembers->CallerMemberDetails;
}else{
$iterateArr[] = $response->CallerMembers->CallerMemberDetails;
}
foreach($iterateArr as $result)
{
$parseResult['firstName'] = $result->firstName;
$parseResult['lastName'] = $result->lastName;
$parseResult['yob'] = substr($result->dob, -4);
if($parseResult['yob'] == $yob)
{
$duplicates++;
}else{
continue;
}
}
// Check for duplicate YoBs
if($duplicates > 1)
{
return "Multiple members with the same YOB";
}elseif($duplicates < 1){
return "No members with the specified YOB found";
}
return $parseResult; // No duplicates, return the record of the matching user
// PROBLEM: Always the last record is returned... not the one with matching YOB?
}
}
That would be because that’s exactly what you told it to do. You’re currently writing every result into
$parseResult– and overwriting the last result in the process – before you even check if it’s the right one. You’re also making thereturncall (as well as the checks) from within theforeachloop, which would actually terminate the loop after the first iteration. What you want is probably more like this: