US State Names & Abbreviations as PHP Array

I needed a PHP array of US State Names & Abbreviations in a project the other day. Here’s four arrays: An entire list of US abbreviations, US State Names, and two associative arrays. Information pulled directly from USPS.Hope it helps!

4 comments

    • I only used one array for the project I was working with, but figured someone might want / need it in a different format and didn’t want to mess with flipping the array, etc. Your function makes a bit more sense than a whole bunch of arrays though πŸ™‚ Thanks!

      • I don’t think β€œmess” was the right word choice there. πŸ˜‰

        You need only a single array: $us_state_abbrevs_names. Then use array_flip() or array_keys() if needed. Having multiple arrays with the same contents is a lot messier and less DRY. (Gist mentioned above seems to be gone, by the way.)

        • Heh yeah you’re absolutely right — I almost don’t want to look at my code from 6 month ago because of stuff like this! But at least I can re-write history and change the gist πŸ™‚

Comments are closed.