topher

Every now and again I find myself needing an html drop down list of US States. I always go hunting around on other people’s forms, and always find lots, but people tend to make them differently, with abbrevs and full names in a variety of positions. Today I got tired of doing that and made my own array, from which I can make whatever I need at the time. And for those of you who may need the same thing, I print it here for you. It’s generic enough that it could easily be used in any language.


$states = array(
'AL'=>'Alabama',
'AK'=>'Alaska',
'AZ'=>'Arizona',
'AR'=>'Arkansas',
'CA'=>'California',
'CO'=>'Colorado',
'CT'=>'Connecticut',
'DE'=>'Delaware',
'FL'=>'Florida',
'GA'=>'Georgia',
'HI'=>'Hawaii',
'ID'=>'Idaho',
'IL'=>'Illinois',
'IN'=>'Indiana',
'IA'=>'Iowa',
'KS'=>'Kansas',
'KY'=>'Kentucky',
'LA'=>'Louisiana',
'ME'=>'Maine',
'MD'=>'Maryland',
'MA'=>'Massachusetts',
'MI'=>'Michigan',
'MN'=>'Minnesota',
'MS'=>'Mississippi',
'MO'=>'Missouri',
'MT'=>'Montana',
'NE'=>'Nebraska',
'NV'=>'Nevada',
'NH'=>'New Hampshire',
'NJ'=>'New Jersey',
'NM'=>'New Mexico',
'NY'=>'New York',
'NC'=>'North Carolina',
'ND'=>'North Dakota',
'OH'=>'Ohio',
'OK'=>'Oklahoma',
'OR'=>'Oregon',
'PA'=>'Pennsylvania',
'RI'=>'Rhode Island',
'SC'=>'South Carolina',
'SD'=>'South Dakota',
'TN'=>'Tennessee',
'TX'=>'Texas',
'UT'=>'Utah',
'VT'=>'Vermont',
'VA'=>'Virginia',
'WA'=>'Washington',
'WV'=>'West Virginia',
'WI'=>'Wisconsin',
'WY'=>'Wyoming'
);

7 thoughts on “States Array

  1. ¡Muchas Gracias, Señor!

    I will add this to my states.txt that I have kept for years, which was just a list of state abbreviations for the same purpose. Way to make it reusable!

  2. Just a few days ago I set up a similar map in Java. I included DC, Puerto Rico, and the Canadian provinces.

    SortedMap statesAndProvinces = new TreeMap() {
    {
    put(” (choose one)”, null);

    put(“Alabama”, “AL”);
    put(“Alaska”, “AK”);
    put(“Arizona”, “AZ”);
    put(“Arkansas”, “AR”);
    put(“California”, “CA”);
    put(“Colorado”, “CO”);
    put(“Connecticut”, “CT”);
    put(“Delaware”, “DE”);
    put(“District of Columbia”, “DC”);
    put(“Florida”, “FL”);
    put(“Georgia”, “GA”);
    put(“Hawaii”, “HI”);
    put(“Idaho”, “ID”);
    put(“Illinois”, “IL”);
    put(“Indiana”, “IN”);
    put(“Iowa”, “IA”);
    put(“Kansas”, “KS”);
    put(“Kentucky”, “KY”);
    put(“Louisiana”, “LA”);
    put(“Maine”, “ME”);
    put(“Maryland”, “MD”);
    put(“Massachusetts”, “MA”);
    put(“Michigan”, “MI”);
    put(“Minnesota”, “MN”);
    put(“Mississippi”, “MS”);
    put(“Missouri”, “MO”);
    put(“Montana”, “MT”);
    put(“Nebraska”, “NB”);
    put(“Nevada”, “NV”);
    put(“New Hampshire”, “NH”);
    put(“New Jersey”, “NJ”);
    put(“New Mexico”, “NM”);
    put(“New York”, “NY”);
    put(“North Carolina”, “NC”);
    put(“North Dakota”, “ND”);
    put(“Ohio”, “OH”);
    put(“Oklahoma”, “OK”);
    put(“Oregon”, “OR”);
    put(“Pennsylvania”, “PA”);
    put(“Puerto Rico”, “PR”);
    put(“Rhode Island”, “RI”);
    put(“South Carolina”, “SC”);
    put(“South Dakota”, “SD”);
    put(“Tennessee”, “TN”);
    put(“Texas”, “TX”);
    put(“Utah”, “UT”);
    put(“Vermont”, “VT”);
    put(“Virginia”, “VA”);
    put(“Washington”, “WA”);
    put(“West Virginia”, “WV”);
    put(“Wisconsin”, “WI”);
    put(“Wyoming”, “WY”);

    put(“Alberta, Canada”, “AB”);
    put(“British Columbia, Canada”, “BC”);
    put(“Manitoba, Canada”, “MB”);
    put(“New Brunswick, Canada”, “NB”);
    put(“Newfoundland, Canada”, “NF”);
    put(“Northwest Territories and Nunavut, Canada”, “NT”);
    put(“Nova Scotia, Canada”, “NS”);
    put(“Ontario, Canada”, “ON”);
    put(“Prince Edward Island, Canada”, “PE”);
    put(“Québec, Canada”, “QC”);
    put(“Sakatchewan, Canada”, “SK”);
    put(“Yukon Territory, Canada”, “YT”);
    }
    };

  3. At AAI they used a database table for this purpose. I thought it was weird at first but now I sort of like the idea.

    When I worked at the Press, it was ingrained into me that you don’t use two-letter postal abbreviations unless you are writing an address. Otherwise you abbreviate Mich., Mass., etc. So you could also include the longer abbreviations in a table, but making a 2-dimensional array for that would be a bit of a pain.

    It also becomes more helpful when you are working with other countries.

  4. I’m a fan of formatting state names like:

    “NY: New York”
    “CA: California”
    “TN: Tennessee”
    etc.

    so that the mapping would end up like:

    “NY” => “NY: New York”,
    “CA” => “CA: California”,
    “TN” => “TN: Tennessee”,
    etc.

    The reason being that I like giving people the ability to type in the abbreviation if they know it (for those people who type in drop-downs), but also the ability to see which state maps to which abbreviation if it’s non-obvious (e.g., ME = Maine).

    $.02

  5. Eek, your posting buttons don’t have a “pressed” state, so I didn’t know it’d registered the click. Hence, the double-post :-/ I swear I’ve used internets before.

  6. Actually Joel, it would be trivial to get the output you want with the array I have. Just print both the key and value between the option tags.

Leave a Reply

Your email address will not be published. Required fields are marked *