Changing the string names of a list

advertisements

Doing this in PHP

I have users input an abbreviation for a city, that gets saved as a string, for example:

ANA BOS VAN

These stand for:
Anaheim
Boston
Vancouver

I want it so that when I get the input/string, it changes the string name to it's full name.

ANA -> Anaheim
BOS -> Boston
VAN -> Vancouver

What is the best way to go about this? Thank you all, greatly appreciated.


update: fixed, so there is no "undefined index" - notice in case you got such a low error_reportinglevel set:

$names["ANA"] = "Anaheim";
$names["BOS"] = "Boston";
$names["VAN"] = "Vancouver";

function getFullName($input, $names)
{
    //turning all input into upper case letters:
    $input = strtoupper($input);

    //making sure input is maximum 3 characters long:
    $input = substr($input, 0, 3);

    if(!array_key_exists($input, $names))
    {
        return "*ERROR: Unknown City Abbreviation*";
    }
    else
    {
        return $names[$input];
    }
}

//usage:
$user_input = "bos";
echo getFullName($user_input, $names);