I have three phone number fields: $PhoneHome, $PhoneWork, and $Mobile. They all may or may not contain data.
I want to concatenate them, and have “(h)”, “(w)”, and “(m)” at the end of each. I also want commas between them.
I have some code which works, but it’s quite long-winded. Is there an easier way of doing it?
[code=php]$NumPhones=0;
if ($PhoneHome!=”) {$NumPhones++;}
if ($PhoneWork!=”) {$NumPhones++;}
if ($Mobile!=”) {$NumPhones++;}
if ($NumPhones==3)
{
$Phone = ($PhoneHome . ‘ (h), ‘ . $PhoneWork . ‘ (w), ‘ . $Mobile . ‘ (m)’);
}
if ($NumPhones==2)
{
if ($PhoneHome!=” && $PhoneWork!=”)
{
$Phone=($PhoneHome . ‘ (h), ‘ . $PhoneWork . ‘ (w)’);
}
if ($PhoneHome!=” && $Mobile!=”)
{
$Phone=($PhoneHome . ‘ (h), ‘ . $Mobile . ‘ (m)’);
}
if ($PhoneWork!=” && $Mobile!=”)
{
$Phone=($PhoneWork . ‘ (h), ‘ . $Mobile . ‘ (m)’);
}
}
if ($NumPhones==1)
{
if ($PhoneHome!=”)
{
$Phone=($PhoneHome . ‘ (h)’);
}
if ($PhoneWork!=”)
{
$Phone=($PhoneWork . ‘ (w)’);
}
if ($Mobile!=”)
{
$Phone=($Mobile . ‘ (w)’);
}
}