Should I store US States in my database or a PHP array?

Because the database is the best way to store it.

What if next year your company decides to go international? So now you need countries, and a dependent dropdown for states.

So you need to add europe, then africa.. Thats a TON of countries, along with a ton of states. You will need one big array.

Then your boss wants a report by country.

Much easier to manage if you have it all in a database.


A wise database designer once told me, "Everything you know about state codes is wrong."

  • These are two-letter codes, not abbreviations. (The abbreviation for California is "Calif.", and the abbreviation for Ohio is "Ohio".)
  • There are more than 50 of them.
  • Not all of the two-letter codes refer to states. They also refer to "possessions" like "Federated States of Micronesia" and "Palau".
  • They're not unique. One two-letter code, AE, refers to four different military "states" (Armed Forces Europe, Armed Forces Canada, Armed Forces Middle East, and Armed Forces Africa).
  • Military "state" codes may change as troop strength changes. Send a few hundred thousand troops into Africa, and you're likely to see the code for Armed Forces Africa change from "AE" to "AF".
  • There are a dozen or so territories that aren't yet in this list. Some of these are of strategic interest (Wake Island, Midway Islands, etc.), and their status could easily change.

Given that you're not likely to know all these things about such a common thing as USPS state codes, it just makes more sense to store them in a table. Tables are easier to maintain at run time than a PHP array is.