I am getting information from a database that I have no control over. The value of “state” is a user entered (and properly cleaned) value, but may be the written out state name or the two letter postal abbreviation. I can easily build an associative array of states and abbreviations. But I was wondering if there is a way, PHP, to determine if a value is in the array of states/abbrev as a key OR a value. So, if you enter “CA” it sees it is a valid two letter key and returns it. If it sees “XY” is NOT a valid key then it retuns a default “OTHER” key (ZZ), but if the user entered input is “New York” it will see it is a valid value and return the associated key, “NY”?
Share
Edit: I’ve changed the loop so that it checks user input against abbreviation and full state name in one condition instead of having them separate.