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
Comments are closed.
Good ref. to USPS, totally forgot about them!
Why do you have so many arrays vs. just one?
Here’s method I use: https://gist.github.com/gists/3176437/ to go from “Maryland” to “md”. Haven’t added support yet to go from “md” to “Maryland”.
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 usearray_flip()
orarray_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 π