This is one of those situations where I'm sure that there's a simple solution, and I need help getting to it.
Suppose we're dealing with three phone numbers: home (h), office (o) and mobile (m). We need to avoid displaying duplicate phone numbers to the end user.
To better explain, here are three sample cases (in PHP):
Case 1:
$phone = array(
'h' => '212-555-1212',
'o' => '212-555-1212',
'm' => '212-555-1212'
);
Should yield:
212-555-1212 (h,o,m)
Case 2:
$phone = array(
'h' => '212-555-1212',
'o' => '212-555-1234', // different
'm' => '212-555-1212'
);
Should yield:
212-555-1212 (h,m)
212-555-1234 (o)
Case 3:
$phone = array(
'h' => null,
'o' => '212-555-1234',
'm' => '212-555-1212'
);
Should yield:
212-555-1234 (o)
212-555-1212 (m)
I have tried using various case statements, by checking for each scenario, but it's complicated by the fact that some values might be empty.
I have also tried using overly-complicated if/elseif/else conditions, but again, it's extremly inelegant.
My best efforts resulted from using array_filter to remove empty elements from the array and the using array_unique to remove duplicates, but then I lose the H/O/M key:
$phone = array_filter(array_unique($phone));
How should I approach this?