I made the website http://devdata.io for this exact reason. You can get an array/list/object of US state names and abbreviations (and lots of other datasets) in any language supported (currently JavaScript, PHP, Python, Ruby, C#, and Lua).
http://statetable.com will give you datasets with US states and/or Canadian provinces, current and/or historical, with or without DC, with or without minor territories & posessions, and with or without military addresses.
Data can be exported in CSV, a PHP array, or a whole mess of MySQL commands to build a table.
I'm surprised PHP doesn't already have US_state_name_to_abbreviation() and US_state_abbreviation_to_name() baked in already. This is a language that supports[0] Swatch Internet time[1]. Literally, a "time" format made up as a gimmick to advertise one specific brand of wristwatch from the late 1990s.
I hope someone on Hacker News who contributes to the PHP core can attempt to correct this discrepancy.
When I developed in PHP, I could never understand why they didn't just reach a compromise that made everyone happy. Like uS_state_nameToAbbreviation() and uSStateAbbr_to_name()