125

US State Names & Abbreviations as PHP Arrays · GitHub

 6 years ago
source link: https://gist.github.com/maxrice/2776900
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

US State Names & Abbreviations as PHP Arrays · GitHub

Instantly share code, notes, and snippets.

US State Names & Abbreviations as PHP Arrays

US States in JSON format, scraped from wikipedia

[
  {
    "abbr": "AL",
    "name": " Alabama"
  },
  {
    "abbr": "AK",
    "name": " Alaska"
  },
  {
    "abbr": "AZ",
    "name": " Arizona"
  },
  {
    "abbr": "AR",
    "name": " Arkansas"
  },
  {
    "abbr": "CA",
    "name": " California"
  },
  {
    "abbr": "CO",
    "name": " Colorado"
  },
  {
    "abbr": "CT",
    "name": " Connecticut"
  },
  {
    "abbr": "DE",
    "name": " Delaware"
  },
  {
    "abbr": "FL",
    "name": " Florida"
  },
  {
    "abbr": "GA",
    "name": " Georgia"
  },
  {
    "abbr": "HI",
    "name": " Hawaii"
  },
  {
    "abbr": "ID",
    "name": " Idaho"
  },
  {
    "abbr": "IL",
    "name": " Illinois"
  },
  {
    "abbr": "IN",
    "name": " Indiana"
  },
  {
    "abbr": "IA",
    "name": " Iowa"
  },
  {
    "abbr": "KS",
    "name": " Kansas"
  },
  {
    "abbr": "KY",
    "name": " Kentucky[E]"
  },
  {
    "abbr": "LA",
    "name": " Louisiana"
  },
  {
    "abbr": "ME",
    "name": " Maine"
  },
  {
    "abbr": "MD",
    "name": " Maryland"
  },
  {
    "abbr": "MA",
    "name": " Massachusetts[E]"
  },
  {
    "abbr": "MI",
    "name": " Michigan"
  },
  {
    "abbr": "MN",
    "name": " Minnesota"
  },
  {
    "abbr": "MS",
    "name": " Mississippi"
  },
  {
    "abbr": "MO",
    "name": " Missouri"
  },
  {
    "abbr": "MT",
    "name": " Montana"
  },
  {
    "abbr": "NE",
    "name": " Nebraska"
  },
  {
    "abbr": "NV",
    "name": " Nevada"
  },
  {
    "abbr": "NH",
    "name": " New Hampshire"
  },
  {
    "abbr": "NJ",
    "name": " New Jersey"
  },
  {
    "abbr": "NM",
    "name": " New Mexico"
  },
  {
    "abbr": "NY",
    "name": " New York"
  },
  {
    "abbr": "NC",
    "name": " North Carolina"
  },
  {
    "abbr": "ND",
    "name": "  North Dakota"
  },
  {
    "abbr": "OH",
    "name": " Ohio"
  },
  {
    "abbr": "OK",
    "name": " Oklahoma"
  },
  {
    "abbr": "OR",
    "name": " Oregon"
  },
  {
    "abbr": "PA",
    "name": " Pennsylvania[E]"
  },
  {
    "abbr": "RI",
    "name": " Rhode Island[F]"
  },
  {
    "abbr": "SC",
    "name": " South Carolina"
  },
  {
    "abbr": "SD",
    "name": " South Dakota"
  },
  {
    "abbr": "TN",
    "name": " Tennessee"
  },
  {
    "abbr": "TX",
    "name": " Texas"
  },
  {
    "abbr": "UT",
    "name": " Utah"
  },
  {
    "abbr": "VT",
    "name": " Vermont"
  },
  {
    "abbr": "VA",
    "name": " Virginia[E]"
  },
  {
    "abbr": "WA",
    "name": " Washington"
  },
  {
    "abbr": "WV",
    "name": " West Virginia"
  },
  {
    "abbr": "WI",
    "name": " Wisconsin"
  },
  {
    "abbr": "WY",
    "name": " Wyoming"
  }
]

Thanks

A bit off topic

// keyed by ISO
$prefectures = [
  'JP-01' => [ 'Hokkaido', '北海道' ],
  'JP-02' => [ 'Aomori', '青森県' ],
  'JP-03' => [ 'Iwate', '岩手県' ],
  'JP-04' => [ 'Miyagi', '宮城県' ],
  'JP-05' => [ 'Akita', '秋田県' ],
  'JP-06' => [ 'Yamagata', '山形県' ],
  'JP-07' => [ 'Fukushima', '福島県' ],
  'JP-08' => [ 'Ibaraki', '茨城県' ],
  'JP-09' => [ 'Tochigi', '栃木県' ],
  'JP-10' => [ 'Gunma', '群馬県' ],
  'JP-11' => [ 'Saitama', '埼玉県' ],
  'JP-12' => [ 'Chiba', '千葉県' ],
  'JP-13' => [ 'Tokyo', '東京都' ],
  'JP-14' => [ 'Kanagawa', '神奈川県' ],
  'JP-15' => [ 'Niigata', '新潟県' ],
  'JP-16' => [ 'Toyama', '富山県' ],
  'JP-17' => [ 'Ishikawa', '石川県' ],
  'JP-18' => [ 'Fukui', '福井県' ],
  'JP-19' => [ 'Yamanashi', '山梨県' ],
  'JP-20' => [ 'Nagano', '長野県' ],
  'JP-21' => [ 'Gifu', '岐阜県' ],
  'JP-22' => [ 'Shizuoka', '静岡県' ],
  'JP-23' => [ 'Aichi', '愛知県' ],
  'JP-24' => [ 'Mie', '三重県' ],
  'JP-25' => [ 'Shiga', '滋賀県' ],
  'JP-26' => [ 'Kyoto', '京都府' ],
  'JP-27' => [ 'Osaka', '大阪府' ],
  'JP-28' => [ 'Hyōgo', '兵庫県' ],
  'JP-29' => [ 'Nara', '奈良県' ],
  'JP-30' => [ 'Wakayama', '和歌山県' ],
  'JP-31' => [ 'Tottori', '鳥取県' ],
  'JP-32' => [ 'Shimane', '島根県' ],
  'JP-33' => [ 'Okayama', '岡山県' ],
  'JP-34' => [ 'Hiroshima', '広島県' ],
  'JP-35' => [ 'Yamaguchi', '山口県' ],
  'JP-36' => [ 'Tokushima', '徳島県' ],
  'JP-37' => [ 'Kagawa', '香川県' ],
  'JP-38' => [ 'Ehime', '愛媛県' ],
  'JP-39' => [ 'Kōchi',	'高知県' ],
  'JP-40' => [ 'Fukuoka', '福岡県' ],
  'JP-41' => [ 'Saga', '佐賀県' ],
  'JP-42' => [ 'Nagasaki', '長崎県' ],
  'JP-43' => [ 'Kumamoto', '熊本県' ],
  'JP-44' => [ 'Ōita', '大分県' ],
  'JP-45' => [ 'Miyazaki', '宮崎県' ],
  'JP-46' => [ 'Kagoshima', '鹿児島県' ],
  'JP-47' => [ 'Okinawa', '沖縄県' ],
]

// keyed by region
$region_prefectures = [
  'Hokkaido' => [
    'JP-01' => [ 'Hokkaido', '北海道' ],
  ],
  'Tōhoku' => [
    'JP-02' => [ 'Aomori', '青森県' ],
    'JP-03' => [ 'Iwate', '岩手県' ],
    'JP-04' => [ 'Miyagi', '宮城県' ],
    'JP-05' => [ 'Akita', '秋田県' ],
    'JP-06' => [ 'Yamagata', '山形県' ],
    'JP-07' => [ 'Fukushima', '福島県' ],    
  ],
  'Kantō' => [
    'JP-08' => [ 'Ibaraki', '茨城県' ],
    'JP-09' => [ 'Tochigi', '栃木県' ],
    'JP-10' => [ 'Gunma', '群馬県' ],
    'JP-11' => [ 'Saitama', '埼玉県' ],
    'JP-12' => [ 'Chiba', '千葉県' ],
    'JP-13' => [ 'Tokyo', '東京都' ],
    'JP-14' => [ 'Kanagawa', '神奈川県' ],
  ],
  'Chūbu' => [
    'JP-15' => [ 'Niigata', '新潟県' ],
    'JP-16' => [ 'Toyama', '富山県' ],
    'JP-17' => [ 'Ishikawa', '石川県' ],
    'JP-18' => [ 'Fukui', '福井県' ],
    'JP-19' => [ 'Yamanashi', '山梨県' ],
    'JP-20' => [ 'Nagano', '長野県' ],
    'JP-21' => [ 'Gifu', '岐阜県' ],
    'JP-22' => [ 'Shizuoka', '静岡県' ],
    'JP-23' => [ 'Aichi', '愛知県' ],    
  ],
  'Kansai' => [
    'JP-24' => [ 'Mie', '三重県' ],
    'JP-25' => [ 'Shiga', '滋賀県' ],
    'JP-26' => [ 'Kyoto', '京都府' ],
    'JP-27' => [ 'Osaka', '大阪府' ],
    'JP-28' => [ 'Hyōgo', '兵庫県' ],
    'JP-29' => [ 'Nara', '奈良県' ],
    'JP-30' => [ 'Wakayama', '和歌山県' ],    
  ],
  'Chūgoku' => [
    'JP-31' => [ 'Tottori', '鳥取県' ],
    'JP-32' => [ 'Shimane', '島根県' ],
    'JP-33' => [ 'Okayama', '岡山県' ],
    'JP-34' => [ 'Hiroshima', '広島県' ],
    'JP-35' => [ 'Yamaguchi', '山口県' ],    
  ],
  'Shikoku' => [
    'JP-36' => [ 'Tokushima', '徳島県' ],
    'JP-37' => [ 'Kagawa', '香川県' ],
    'JP-38' => [ 'Ehime', '愛媛県' ],
    'JP-39' => [ 'Kōchi',	'高知県' ],    
  ],
  'Kyushu' => [
    'JP-40' => [ 'Fukuoka', '福岡県' ],
    'JP-41' => [ 'Saga', '佐賀県' ],
    'JP-42' => [ 'Nagasaki', '長崎県' ],
    'JP-43' => [ 'Kumamoto', '熊本県' ],
    'JP-44' => [ 'Ōita', '大分県' ],
    'JP-45' => [ 'Miyazaki', '宮崎県' ],
    'JP-46' => [ 'Kagoshima', '鹿児島県' ],
    'JP-47' => [ 'Okinawa', '沖縄県' ],    
  ],
]

crussell52 commented on Mar 20, 2019

edited

Here is a list of all the climber states for FRC Team 1251's 2019 Robot...

    private enum ClimbState {
        INITIALIZING,
        LIFTING,
        GAINING_FOOTHOLD, 
        TRIGGERING_RETRACT_FRONT, 
        RETRACTING_FRONT, 
        GAINING_BALANCE, 
        RETRACTING_BACK, 
        FINISHING, 
        ALL_THE_POINTS
    }

#FIRSTinspires #makeitloud

The comments on here got out of control and I'm afraid that the original list may be lost for some users. So I'm posting it again to help those users out.

$us_state_abbrevs_names = array(
	'AL' => 'ALABAMA',
	'AK' => 'ALASKA',
	'AS' => 'AMERICAN SAMOA',
	'AZ' => 'ARIZONA',
	'AR' => 'ARKANSAS',
	'CA' => 'CALIFORNIA',
	'CO' => 'COLORADO',
	'CT' => 'CONNECTICUT',
	'DE' => 'DELAWARE',
	'DC' => 'DISTRICT OF COLUMBIA',
	'FM' => 'FEDERATED STATES OF MICRONESIA',
	'FL' => 'FLORIDA',
	'GA' => 'GEORGIA',
	'GU' => 'GUAM GU',
	'HI' => 'HAWAII',
	'ID' => 'IDAHO',
	'IL' => 'ILLINOIS',
	'IN' => 'INDIANA',
	'IA' => 'IOWA',
	'KS' => 'KANSAS',
	'KY' => 'KENTUCKY',
	'LA' => 'LOUISIANA',
	'ME' => 'MAINE',
	'MH' => 'MARSHALL ISLANDS',
	'MD' => 'MARYLAND',
	'MA' => 'MASSACHUSETTS',
	'MI' => 'MICHIGAN',
	'MN' => 'MINNESOTA',
	'MS' => 'MISSISSIPPI',
	'MO' => 'MISSOURI',
	'MT' => 'MONTANA',
	'NE' => 'NEBRASKA',
	'NV' => 'NEVADA',
	'NH' => 'NEW HAMPSHIRE',
	'NJ' => 'NEW JERSEY',
	'NM' => 'NEW MEXICO',
	'NY' => 'NEW YORK',
	'NC' => 'NORTH CAROLINA',
	'ND' => 'NORTH DAKOTA',
	'MP' => 'NORTHERN MARIANA ISLANDS',
	'OH' => 'OHIO',
	'OK' => 'OKLAHOMA',
	'OR' => 'OREGON',
	'PW' => 'PALAU',
	'PA' => 'PENNSYLVANIA',
	'PR' => 'PUERTO RICO',
	'RI' => 'RHODE ISLAND',
	'SC' => 'SOUTH CAROLINA',
	'SD' => 'SOUTH DAKOTA',
	'TN' => 'TENNESSEE',
	'TX' => 'TEXAS',
	'UT' => 'UTAH',
	'VT' => 'VERMONT',
	'VI' => 'VIRGIN ISLANDS',
	'VA' => 'VIRGINIA',
	'WA' => 'WASHINGTON',
	'WV' => 'WEST VIRGINIA',
	'WI' => 'WISCONSIN',
	'WY' => 'WYOMING',
	'AE' => 'ARMED FORCES AFRICA \ CANADA \ EUROPE \ MIDDLE EAST',
	'AA' => 'ARMED FORCES AMERICA (EXCEPT CANADA)',
	'AP' => 'ARMED FORCES PACIFIC',
);

filconty commented on Jun 29, 2019

edited
/**
 * State Abbreviations
 *
 * Converts state names to abbreviations and visa versa, correcting case
 * Provide 2 letter abbr to get name, or partial names to get abbr
 * apply 'true' as arg to force abbreviation or returns false
 * returns capialized names that are not recognized if no 'true' arg
 * applies to USA, territories, Armed Forces, & Canadian Provinces
 *
 * @example echo state_abbr('oK'); // Oklahoma
 * @example echo state_abbr(' oK  '); // Oklahoma
 * @example echo state_abbr('oKlHoMa'); // OK
 * @example echo state_abbr('oK',true); // OK
 * @example echo state_abbr(' oK  ',true); // OK
 * @example echo state_abbr(' oklaho  '); // OK
 * @example echo state_abbr(' oklaho  ',true); // OK
 * @example echo state_abbr('nh '); // New Hampshire
 * @example echo state_abbr('nh ',true); // NH
 * @example echo state_abbr('hamp   '); // NH
 * @example echo state_abbr('new ham  ',true); // NH
 */

function state_abbr($name,$req) {
    $states = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','dist of columbia'=>'DC','dist. of columbia'=>'DC','district of columbia'=>'DC','florida'=>'FL','georgia'=>'GA','guam'=>'GU','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','puerto rico'=>'PR','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virgin islands'=>'VI','virginia'=>'VA','washington'=>'WA','washington d.c.'=>'DC','washington dc'=>'DC','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','armed forces africa'=>'AF','armed forces americas'=>'AA','armed forces canada'=>'AC','armed forces europe'=>'AE','armed forces middle east'=>'AM','armed forces pacific'=>'AP','alberta'=>'AB','british columbia'=>'BC','manitoba'=>'MB','new brunswick'=>'NB','newfoundland & labrador'=>'NL','northwest territories'=>'NT','nova scotia'=>'NS','nunavut'=>'NU','ontario'=>'ON','prince edward island'=>'PE','quebec'=>'QC','saskatchewan'=>'SK','yukon territory'=>'YT');
    if ($name) $name = trim($name);
    if (strlen($name) == 2) {
        if ($req) return strtoupper($name);
        $states = array_flip($states);
        $new = str_replace('Dc','DC',ucwords($states[strtoupper($name)]));
    } elseif (strlen($name) > 2) {
        $new = $states[strtolower($name)];
        if (!$new) {
            foreach ($states as $str => $res) {
                if (strpos($str,$name) !== false) $state[] .= $res;
            }
            if (count($state) < 2) return ($state[0]) ? $state[0] : false;

// What do you want to do if function finds more than 1 state that fits?
// The default returns false if the "true" arg is used but you can return
// an array with all possible states by enabling the following line
//           else $new = $state;

        }
    }
    return ($new) ? $new : (isset($req) ? false : ucwords(strtolower($name)));
}

hi, nice code. i think this will work for me. i have descriptions that have partial state names and i need a new column to report the state abbreviation. i tried doing this but received the name error so i must be doing something wrong, can you provide instructions on how to do his for what i described. im not savvy on the programming end

filconty commented on Jul 3, 2019

edited

Thanks. Whenever possible, I try to make code fix errors instead of just throwing them back to the users. That is why it takes so many possible mistakes and resolves a PRESUMABLY accurate name from them. Frankly, I wrote it and then added it to the Github page because I wasn’t satisfied with the others I found there and knew I could improve. But to be honest, there are potential flaws. For example, my own application includes the possibility of states/province/other in any country around the world, so it allows any 2-letter to pass, including something like "ZZ" which is not a state in the USA and probably not any other nation either.

As for how to apply it, I'm not sure what you are trying to do. Assuming that you have an array with the states that you want it to apply to, you can just apply it to each one with a loop, such as:

// $array = your array with the states in it
$array = array('alab','alas','ariz','new m','york','sc','wis');
foreach ($array as $state) {
        $newStates[].=state_abbr($state,true);
}
print_r($newStates); // Array ( [0] => AL [1] => AK [2] => AZ [3] => NM [4] => NY [5] => SC [6] => WI )

Thank you!

From: MoreWho <[email protected]> Sent: Wednesday, July 3, 2019 8:12 AM To: maxrice <[email protected]> Cc: Sal Favarolo <[email protected]>; Comment <[email protected]> Subject: Re: maxrice/us-state-names-abbrevs.php

Whenever possible, I try to make code fix errors instead of just throwing them back to the users. That is why it takes so many possible mistakes and resolves a PRESUMABLY accurate name from them. Frankly, I wrote it and then added it to the Github page because I wasn’t satisfied with the others I found there and knew I could improve. But to be honest, there are potential flaws. For example, if a user enters “new h” or “new y” or “new m” as a state, it will throw back the assumed abbreviations of NH, NY, or NM. But if they just enter “new”, it throws back the first one it finds in test, which is NY. I need to make a change to it to catch and throw back error in that case. Give me a couple hours.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub<https://gist.github.com/2776900?email_source=notifications&email_token=AMP7USW2C2EM5CDVZPSWX33P5SJR7A5CNFSM4HNF6PVKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFUW46#gistcomment-2960847>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AMP7USUXMJINUK4BRMCV7VLP5SJR7ANCNFSM4HNF6PVA>.

How is this implemented in excel? Where I have a column with descriptions such as SHAKER HEIGHTS OHIO PUB LIBR C COPS 2019, or MONMOUTH N J REGL HIGH SCH DIS BDS, LAKE WORTH FLA GO BDS 2018, SAN ELIZARIO TEX INDPT SCH DIS ULTD TAX SCH BLDG BDS 2015, and the next column I want the state abbreviation.

From: MoreWho <[email protected]> Sent: Wednesday, July 3, 2019 8:12 AM To: maxrice <[email protected]> Cc: Sal Favarolo <[email protected]>; Comment <[email protected]> Subject: Re: maxrice/us-state-names-abbrevs.php

Whenever possible, I try to make code fix errors instead of just throwing them back to the users. That is why it takes so many possible mistakes and resolves a PRESUMABLY accurate name from them. Frankly, I wrote it and then added it to the Github page because I wasn’t satisfied with the others I found there and knew I could improve. But to be honest, there are potential flaws. For example, if a user enters “new h” or “new y” or “new m” as a state, it will throw back the assumed abbreviations of NH, NY, or NM. But if they just enter “new”, it throws back the first one it finds in test, which is NY. I need to make a change to it to catch and throw back error in that case. Give me a couple hours.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub<https://gist.github.com/2776900?email_source=notifications&email_token=AMP7USW2C2EM5CDVZPSWX33P5SJR7A5CNFSM4HNF6PVKYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFUW46#gistcomment-2960847>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AMP7USUXMJINUK4BRMCV7VLP5SJR7ANCNFSM4HNF6PVA>.

Wow, I fixed the code as described earlier but I have given it some thought and don't see a simple solution for your latest problem. Apparently, your data includes the states within it however there is no rule that seems to simplify identification and extraction of that information. For example, the state information is presented in different styles and different locations within each record, such as the entire word "OHIO" in 3rd spot of first record, the letters "N J" with space between them in second spot of next record, and Florida abbreviated as "FLA" in 3rd spot of next record. My code would be able to provide abbreviations if you parse the records and try each segment, but it wouldn't find Florida because the abbreviation is wrong and it wouldn't find New Jersey because of the space. And it would very likely mistake other records if the address included words that could be parsed into state names or abbreviations.

In your case, I believe I would use code to check Google maps for each address, and see if they can return a record that identifies the state. I'm sorry, but I'm pretty busy at the moment and don't have time to write that code for you and besides, someone probably has already done it if you look.

jmonday-ci commented on Oct 2, 2019

edited

$states = [

image

];

download

Here's an awesome car to drive around in all the states with:

1970-chevrolet-chevelle-ls6-ss454

aolin480 commented on Oct 3, 2019

edited

Here are states that were individually rated 1-10 by my awesome cat!

<?php

$wifeStateRatings = [
    'ALABAMA' => '3',
    'ALABAMA' => '8',
    'ALASKA' => '10',
    'ARIZONA' => '10',
    'ARKANSAS' => '6',
    'CALIFORNIA' => '3',
    'COLORADO' => '3',
    'CONNECTICUT' => '8',
    'DELAWARE' => '6',
    'FLORIDA' => '5',
    'GEORGIA' => '7',
    'HAWAII' => '10',
    'IDAHO' => '6',
    'ILLINOIS' => '4',
    'INDIANA' => '3',
    'IOWA' => '3',
    'KANSAS' => '8',
    'KENTUCKY' => '9',
    'LOUISIANA' => '7',
    'MAINE' => '7',
    'MARYLAND' => '5',
    'MASSACHUSETTS' => '10',
    'MICHIGAN' => '10',
    'MINNESOTA' => '3',
    'MISSISSIPPI' => '5',
    'MISSOURI' => '4',
    'MONTANA' => '10',
    'NEBRASKA' => '6',
    'NEVADA' => '9',
    'NEW HAMPSHIRE' => '5',
    'NEW JERSEY' => '7',
    'NEW MEXICO' => '10',
    'NEW YORK' => '1',
    'NORTH CAROLINA' => '2',
    'NORTH DAKOTA' => '3',
    'OHIO' => '8',
    'OKLAHOMA' => '6',
    'OREGON' => '10',
    'PENNSYLVANIA' => '10',
    'RHODE ISLAND' => '1',
    'SOUTH CAROLINA' => '9',
    'SOUTH DAKOTA' => '10',
    'TENNESSEE' => '5',
    'TEXAS' => '1',
    'UTAH' => '2',
    'VERMONT' => '2',
    'VIRGINIA' => '7',
    'WASHINGTON' => '5',
    'WEST VIRGINIA' => '9',
    'WISCONSIN' => '7',
    'WYOMING' => '4',
];

?>

kijube commented on Apr 15, 2020

edited

In case anyone else needs it: State names and abbreviations without the same characters next to each other (like "BB").



$us_state_abbrevs_names = array(
	'AL' => 'ALABAMA',
	'AK' => 'ALASKA',
	'AS' => 'AMERICAN SAMOA',
	'AZ' => 'ARIZONA',
	'AR' => 'ARKANSAS',
	'CA' => 'CALIFORNIA',
	'CO' => 'COLORADO',
	'CT' => 'CONECTICUT',
	'DE' => 'DELAWARE',
	'DC' => 'DISTRICT OF COLUMBIA',
	'FM' => 'FEDERATED STATES OF MICRONESIA',
	'FL' => 'FLORIDA',
	'GA' => 'GEORGIA',
	'GU' => 'GUAM GU',
	'HI' => 'HAWAI',
	'ID' => 'IDAHO',
	'IL' => 'ILINOIS',
	'IN' => 'INDIANA',
	'IA' => 'IOWA',
	'KS' => 'KANSAS',
	'KY' => 'KENTUCKY',
	'LA' => 'LOUISIANA',
	'ME' => 'MAINE',
	'MH' => 'MARSHAL ISLANDS',
	'MD' => 'MARYLAND',
	'MA' => 'MASACHUSETS',
	'MI' => 'MICHIGAN',
	'MN' => 'MINESOTA',
	'MS' => 'MISISIPI',
	'MO' => 'MISOURI',
	'MT' => 'MONTANA',
	'NE' => 'NEBRASKA',
	'NV' => 'NEVADA',
	'UH' => 'US HAMPSHIRE',
	'AJ' => 'AMERICAN JERSEY',
	'MU' => 'MEXICO BUT IN THE US',
	'BY' => 'THE BIG YORK',
	'NC' => 'NORTH CAROLINA',
	'ND' => 'NORTH DAKOTA',
	'MP' => 'NORTHERN MARIANA ISLANDS',
	'OH' => 'OHIO',
	'OK' => 'OKLAHOMA',
	'OR' => 'OREGON',
	'PW' => 'PALAU',
	'PA' => 'PENSYLVANIA',
	'PR' => 'PUERTO RICO',
	'RI' => 'RHODE ISLAND',
	'SC' => 'SOUTH CAROLINA',
	'SD' => 'SOUTH DAKOTA',
	'TN' => 'TENESE',
	'TX' => 'TEXAS',
	'UT' => 'UTAH',
	'VT' => 'VERMONT',
	'VI' => 'VIRGIN ISLANDS',
	'VA' => 'VIRGINIA',
	'WA' => 'WASHINGTON',
	'WV' => 'WEST VIRGINIA',
	'WI' => 'WISCONSIN',
	'WY' => 'WYOMING',
	'AE' => 'ARMED FORCES AFRICA \ CANADA \ EUROPE \ MIDLE EAST',
	'A' => 'ARMED FORCES AMERICA (EXCEPT CANADA)',
	'AP' => 'ARMED FORCES PACIFIC',
);

?>

//Edit: I also removed the "New" from all the states as they have existed for a long time and I feel like they shouldn't be called "new" anymore.
//Edit2: I noticed that New Mexico is now called "Mexico", so I changed the name to "MEXICO BUT IN THE US".
//Edit3: Same for York
//edit4: .... and for Hampshire and Jersey

Here is a function that you can pass in the state name, and get the abbreviation back. Based on a few comments from this amusing thread. Includes Canadian provinces, since I needed those.

function state_abreviation_for( $state ) {
 // from https://gist.github.com/maxrice/2776900 and http://www.comeexplorecanada.com/abbreviations.php
 static $states = ['ALABAMA' => 'AL', 'ALASKA' => 'AK', 'ARIZONA' => 'AZ', 'ARKANSAS' => 'AR', 'CALIFORNIA' => 'CA', 'COLORADO' => 'CO', 'CONNECTICUT' => 'CT', 'DELAWARE' => 'DE', 'FLORIDA' => 'FL', 'GEORGIA' => 'GA', 'HAWAII' => 'HI', 'IDAHO' => 'ID', 'ILLINOIS' => 'IL', 'INDIANA' => 'IN', 'IOWA' => 'IA', 'KANSAS' => 'KS', 'KENTUCKY' => 'KY', 'LOUISIANA' => 'LA', 'MAINE' => 'ME', 'MARYLAND' => 'MD', 'MASSACHUSETTS' => 'MA', 'MICHIGAN' => 'MI', 'MINNESOTA' => 'MN', 'MISSISSIPPI' => 'MS', 'MISSOURI' => 'MO', 'MONTANA' => 'MT', 'NEBRASKA' => 'NE', 'NEVADA' => 'NV', 'NEW HAMPSHIRE' => 'NH', 'NEW JERSEY' => 'NJ', 'NEW MEXICO' => 'NM', 'NEW YORK' => 'NY', 'NORTH CAROLINA' => 'NC', 'NORTH DAKOTA' => 'ND', 'OHIO' => 'OH', 'OKLAHOMA' => 'OK', 'OREGON' => 'OR', 'PENNSYLVANIA' => 'PA', 'RHODE ISLAND' => 'RI', 'SOUTH CAROLINA' => 'SC', 'SOUTH DAKOTA' => 'SD', 'TENNESSEE' => 'TN', 'TEXAS' => 'TX', 'UTAH' => 'UT', 'VERMONT' => 'VT', 'VIRGINIA' => 'VA', 'WASHINGTON' => 'WA', 'WEST VIRGINIA' => 'WV', 'WISCONSIN' => 'WI', 'WYOMING' => 'WY', 'ALBERTA' => 'AB', 'BRITISH COLUMBIA' => 'BC', 'MANITOBA' => 'MB', 'NEW BRUNSWICK' => 'NB', 'NEWFOUNDLAND AND LABRADOR' => 'NL', 'NOVA SCOTIA' => 'NS', 'NORTWEST TERRITORIES' => 'NT', 'NUNAVUT' => 'NU', 'ONTARIO' => 'ON', 'PRINCE EDWARD ISLAND' => 'PE', 'QUEBEC' => 'QC', 'SASKATCHEWAN' => 'SK', 'YUKON' => 'YT', 'PUERTO RICO' => 'PR', 'VIRGIN ISLANDS' => 'VI', 'WASHINGTON DC' => 'DC'];

 // first check if input is two letters, and if so make sure that it matches one of the abbreviations, then return that
 if ( strlen( $state ) == 2 ) {
   if ( in_array( strtoupper( $state ), $states ) ) {
      return strtoupper( $state );
   } else {
    return null;
  }
}

   // check for the full state name in the array
  if ( array_key_exists( strtoupper( $state ), $states ) ) {
    return $states[strtoupper( $state )];
  } else {
    return null;
  }
}

If it is a two letter string it checks to ensure that it is a state abbreviation, then returns the uppercase form of that, or null if not found in the array. If it is anything longer it checks to see if it is a key in the array, and returns the abbreviation, or null if not found.

Here is a function that you can pass in the state name, and get the abbreviation back. Based on a few comments from this amusing thread. Includes Canadian provinces, since I needed those.

function state_abreviation_for( $state ) {
 // from https://gist.github.com/maxrice/2776900 and http://www.comeexplorecanada.com/abbreviations.php
 static $states = ['ALABAMA' => 'AL', 'ALASKA' => 'AK', 'ARIZONA' => 'AZ', 'ARKANSAS' => 'AR', 'CALIFORNIA' => 'CA', 'COLORADO' => 'CO', 'CONNECTICUT' => 'CT', 'DELAWARE' => 'DE', 'FLORIDA' => 'FL', 'GEORGIA' => 'GA', 'HAWAII' => 'HI', 'IDAHO' => 'ID', 'ILLINOIS' => 'IL', 'INDIANA' => 'IN', 'IOWA' => 'IA', 'KANSAS' => 'KS', 'KENTUCKY' => 'KY', 'LOUISIANA' => 'LA', 'MAINE' => 'ME', 'MARYLAND' => 'MD', 'MASSACHUSETTS' => 'MA', 'MICHIGAN' => 'MI', 'MINNESOTA' => 'MN', 'MISSISSIPPI' => 'MS', 'MISSOURI' => 'MO', 'MONTANA' => 'MT', 'NEBRASKA' => 'NE', 'NEVADA' => 'NV', 'NEW HAMPSHIRE' => 'NH', 'NEW JERSEY' => 'NJ', 'NEW MEXICO' => 'NM', 'NEW YORK' => 'NY', 'NORTH CAROLINA' => 'NC', 'NORTH DAKOTA' => 'ND', 'OHIO' => 'OH', 'OKLAHOMA' => 'OK', 'OREGON' => 'OR', 'PENNSYLVANIA' => 'PA', 'RHODE ISLAND' => 'RI', 'SOUTH CAROLINA' => 'SC', 'SOUTH DAKOTA' => 'SD', 'TENNESSEE' => 'TN', 'TEXAS' => 'TX', 'UTAH' => 'UT', 'VERMONT' => 'VT', 'VIRGINIA' => 'VA', 'WASHINGTON' => 'WA', 'WEST VIRGINIA' => 'WV', 'WISCONSIN' => 'WI', 'WYOMING' => 'WY', 'ALBERTA' => 'AB', 'BRITISH COLUMBIA' => 'BC', 'MANITOBA' => 'MB', 'NEW BRUNSWICK' => 'NB', 'NEWFOUNDLAND AND LABRADOR' => 'NL', 'NOVA SCOTIA' => 'NS', 'NORTWEST TERRITORIES' => 'NT', 'NUNAVUT' => 'NU', 'ONTARIO' => 'ON', 'PRINCE EDWARD ISLAND' => 'PE', 'QUEBEC' => 'QC', 'SASKATCHEWAN' => 'SK', 'YUKON' => 'YT', 'PUERTO RICO' => 'PR', 'VIRGIN ISLANDS' => 'VI', 'WASHINGTON DC' => 'DC'];

 // first check if input is two letters, and if so make sure that it matches one of the abbreviations, then return that
 if ( strlen( $state ) == 2 ) {
   if ( in_array( strtoupper( $state ), $states ) ) {
      return strtoupper( $state );
   } else {
    return null;
  }
}

   // check for the full state name in the array
  if ( array_key_exists( strtoupper( $state ), $states ) ) {
    return $states[strtoupper( $state )];
  } else {
    return null;
  }
}

If it is a two letter string it checks to ensure that it is a state abbreviation, then returns the uppercase form of that, or null if not found in the array. If it is anything longer it checks to see if it is a key in the array, and returns the abbreviation, or null if not found.

Awesome. Thanks

nbrombal commented on May 6, 2021

edited

Here is a PHP array of US states & territories keyed by the cumulative total of all ZIP codes within their borders:

$state_zip_code_totals = [
    13168     => 'VI',
    96799     => 'AS',
    140075    => 'PR',
    193879    => 'PW',
    193930    => 'MH',
    260688    => 'RI',
    290853    => 'MP',
    387770    => 'FM',
    991495    => 'NH',
    1259966   => 'GU',
    1338256   => 'MA',
    1696720   => 'VT',
    1906928   => 'AA',
    1946248   => 'DE',
    2187658   => 'ME',
    2814858   => 'CT',
    4350704   => 'AE',
    5819302   => 'NJ',
    6597739   => 'DC',
    13199122  => 'MD',
    13452400  => 'HI',
    15919979  => 'SC',
    16101058  => 'WY',
    19197510  => 'AP',
    20864380  => 'MS',
    22048513  => 'WV',
    22609881  => 'SD',
    22679051  => 'NV',
    23837397  => 'ND',
    24084963  => 'MT',
    27151742  => 'ID',
    27312212  => 'AK',
    27845593  => 'NY',
    28797817  => 'VA',
    29359808  => 'UT',
    30070901  => 'TN',
    30155013  => 'AL',
    30285870  => 'GA',
    30585902  => 'NC',
    37530312  => 'NM',
    38098744  => 'PA',
    39881387  => 'KY',
    42629108  => 'NE',
    46588515  => 'IN',
    47829299  => 'OR',
    48542656  => 'WI',
    48607861  => 'AZ',
    49744409  => 'FL',
    50702440  => 'KS',
    51307976  => 'LA',
    51336487  => 'AR',
    53456968  => 'CO',
    54458540  => 'IA',
    57285510  => 'MI',
    57376000  => 'OK',
    57656436  => 'MN',
    64342337  => 'OH',
    72268165  => 'WA',
    75564998  => 'MO',
    97879345  => 'IL',
    206507257 => 'TX',
    248018835 => 'CA',
];

This is extremely useful if you would enjoy spending several hours verifying whether a random internet user would really go to the trouble of posting accurate data for something that has absolutely no practical use whatsoever in a format that foregoes any semblance of usability.

Author

maxrice commented on May 8, 2021

@nbrombal thanks! that's exactly what I needed for a project I've been working on smirk_cat

Here's a switch statement (in alphabetical order):

switch($us_state) {
case "Alabama":
return 0.01;
break;
case "Alaska":
return 0.02;
break;
case "Arizona":
return 0.01;
break;
case "Arkansas":
return 0.01;
break;
case "California":
return 0.01;
break;
case "Colorado":
return 0.01;
break;
case "Connecticut":
return 0.01;
break;
case "Delaware":
return 0.01;
break;
case "Florida":
return 0.01;
break;
case "Georgia":
return 0.01;
break;
case "Hawaii":
return 0.01;
break;
case "Idaho":
return 0.01;
break;
case "Illinois":
return 0.01;
break;
case "Indiana":
return 0.01;
break;
case "Iowa":
return 0.01;
break;
case "Kansas":
return 0.01;
break;
case "Kentucky":
return 0.01;
break;
case "Louisiana":
return 0.01;
break;
case "Maine":
return 0.01;
break;
case "Maryland":
return 0.01;
break;
case "Massachusetts":
return 0.01;
break;
case "Michigan":
return 0.01;
break;
case "Minnesota":
return 0.01;
break;
case "Mississippi":
return 0.01;
break;
case "Missouri":
return 0.01;
break;
case "Montana":
return 0.01;
break;
case "Nebraska":
return 0.01;
break;
case "Nevada":
return 0.01;
break;
case "New Hampshire":
return 0.01;
break;
case "New Jersey":
return 0.01;
break;
case "New Mexico":
return 0.01;
break;
case "New York":
return 0.01;
break;
case "North Carolina":
return 0.01;
break;
case "North Dakota":
return 0.01;
break;
case "Ohio":
return 0.01;
break;
case "Oklahoma":
return 0.01;
break;
case "Oregon":
return 0.01;
break;
case "Pennsylvania":
return 0.01;
break;
case "Rhode Island":
return 0.01;
break;
case "South Carolina":
return 0.01;
break;
case "South Dakota":
return 0.01;
break;
case "Tennessee":
return 0.01;
break;
case "Texas":
return 0.01;
break;
case "Utah":
return 0.01;
break;
case "Vermont":
return 0.01;
break;
case "Virginia":
return 0.01;
break;
case "Washington":
return 0.01;
break;
case "West Virginia":
return 0.01;
break;
case "Wisconsin":
return 0.01;
break;
case "Wyoming":
return 0.01;
break;
}

Here is a php array of all the states and abbreviations in binary

$us_states_binary = array(
    '01000001 01001100' => '01000001 01101100 01100001 01100010 01100001 01101101 01100001'
    '01000001 01001011' => '01000001 01101100 01100001 01110011 01101011 01100001'
    '01000001 01011010' => '01000001 01110010 01101001 01111010 01101111 01101110 01100001'
    '01000001 01010010' => '01000001 01110010 01101011 01100001 01101110 01110011 01100001 01110011'
    '01000011 01000001' => '01000011 01100001 01101100 01101001 01100110 01101111 01110010 01101110 01101001 01100001'
    '01000011 01001111' => '01000011 01101111 01101100 01101111 01110010 01100001 01100100 01101111'
    '01000011 01010100' => '01000011 01101111 01101110 01101110 01100101 01100011 01110100 01101001 01100011 01110101 01110100'
    '01000100 01000101' => '01000100 01100101 01101100 01100001 01110111 01100001 01110010 01100101'
    '01000100 01000011' => '01000100 01101001 01110011 01110100 01110010 01101001 01100011 01110100 00100000 01101111 01100110 00100000 01000011 01101111 01101100 01110101 01101101 0110001001101001 01100001'
    '01000110 01001100' => '01000110 01101100 01101111 01110010 01101001 01100100 01100001'
    '01000111 01000001' => '01000111 01100101 01101111 01110010 01100111 01101001 01100001'
    '01001000 01001001' => '01001000 01100001 01110111 01100001 01101001 01101001'
    '01001001 01000100' => '01001001 01100100 01100001 01101000 01101111'
    '01001001 01001100' => '01001001 01101100 01101100 01101001 01101110 01101111 01101001 01110011'
    '01001001 01001110' => '01001001 01101110 01100100 01101001 01100001 01101110 01100001'
    '01001001 01000001' => '01001001 01101111 01110111 01100001'
    '01001011 01010011' => '01001011 01100001 01101110 01110011 01100001 01110011'
    '01001011 01011001' => '01001011 01100101 01101110 01110100 01110101 01100011 01101011 01111001'
    '01001100 01000001' => '01001100 01101111 01110101 01101001 01110011 01101001 01100001 01101110 01100001'
    '01001101 01000101' => '01001101 01100001 01101001 01101110 01100101'
    '01001101 01000100' => '01001101 01100001 01110010 01111001 01101100 01100001 01101110 01100100'
    '01001101 01000001' => '01001101 01100001 01110011 01110011 01100001 01100011 01101000 01110101 01110011 01100101 01110100 01110100 01110011'
    '01001101 01001001' => '01001101 01101001 01100011 01101000 01101001 01100111 01100001 01101110'
    '01001101 01001110' => '01001101 01101001 01101110 01101110 01100101 01110011 01101111 01110100 01100001'
    '01001101 01010011' => '01001101 01101001 01110011 01110011 01101001 01110011 01110011 01101001 01110000 01110000 01101001'
    '01001101 01001111' => '01001101 01101001 01110011 01110011 01101111 01110101 01110010 01101001'
    '01001101 01010100' => '01001101 01101111 01101110 01110100 01100001 01101110 01100001'
    '01001110 01000101' => '01001110 01100101 01100010 01110010 01100001 01110011 01101011 01100001'
    '01001110 01010110' => '01001110 01100101 01110110 01100001 01100100 01100001'
    '01001110 01001000' => '01001110 01100101 01110111 00100000 01001000 01100001 01101101 01110000 01110011 01101000 01101001 01110010 01100101'
    '01001110 01001010' => '01001110 01100101 01110111 00100000 01001010 01100101 01110010 01110011 01100101 01111001'
    '01001110 01001101' => '01001110 01100101 01110111 00100000 01001101 01100101 01111000 01101001 01100011 01101111'
    '01001110 01011001' => '01001110 01100101 01110111 00100000 01011001 01101111 01110010 01101011'
    '01001110 01000011' => '01001110 01101111 01110010 01110100 01101000 00100000 01000011 01100001 01110010 01101111 01101100 01101001 01101110 01100001'
    '01001110 01000100' => '01001110 01101111 01110010 01110100 01101000 00100000 01000100 01100001 01101011 01101111 01110100 01100001'
    '01001111 01001000' => '01001111 01101000 01101001 01101111'
    '01001111 01001011' => '01001111 01101011 01101100 01100001 01101000 01101111 01101101 01100001'
    '01001111 01010010' => '01001111 01110010 01100101 01100111 01101111 01101110'
    '01010000 01000001' => '01010000 01100101 01101110 01101110 01110011 01111001 01101100 01110110 01100001 01101110 01101001 01100001'
    '01010010 01001001' => '01010010 01101000 01101111 01100100 01100101 00100000 01001001 01110011 01101100 01100001 01101110 01100100'
    '01010011 01000011' => '01010011 01101111 01110101 01110100 01101000 00100000 01000011 01100001 01110010 01101111 01101100 01101001 01101110 01100001'
    '01010011 01000100' => '01010011 01101111 01110101 01110100 01101000 00100000 01000100 01100001 01101011 01101111 01110100 01100001'
    '01010100 01001110' => '01010100 01100101 01101110 01101110 01100101 01110011 01110011 01100101 01100101'
    '01010100 01011000' => '01010100 01100101 01111000 01100001 01110011'
    '01010101 01010100' => '01010101 01110100 01100001 01101000'
    '01010110 01010100' => '01010110 01100101 01110010 01101101 01101111 01101110 01110100'
    '01010110 01000001' => '01010110 01101001 01110010 01100111 01101001 01101110 01101001 01100001'
    '01010111 01000001' => '01010111 01100001 01110011 01101000 01101001 01101110 01100111 01110100 01101111 01101110'
    '01010111 01010110' => '01010111 01100101 01110011 01110100 00100000 01010110 01101001 01110010 01100111 01101001 01101110 01101001 01100001'
    '01010111 01001001' => '01010111 01101001 01110011 01100011 01101111 01101110 01110011 01101001 01101110'
    '01010111 01011001' => '01010111 01111001 01101111 01101101 01101001 01101110 01100111'
);

This is useful if you want to take the time and decode all of this.

In case you live in Europe, like me:

$states = array();

State names, but without the vowels:

$stateNames = [
    'AL'=>'lbm',
    'AK'=>'lsk',
    'AS'=>'mrcn sm',
    'AZ'=>'rzn',
    'AR'=>'rknss',
    'CA'=>'Clfrn',
    'CO'=>'Clrd',
    'CT'=>'Cnnctct',
    'DE'=>'Dlwr',
    'DC'=>'Dstrct f Clmb',
    'FM'=>'Fdrtd Stts f Mcrns',
    'FL'=>'Flrd',
    'GA'=>'Grg',
    'GU'=>'Gm G',
    'HI'=>'Hw',
    'ID'=>'dh',
    'IL'=>'llns',
    'IN'=>'ndn',
    'IA'=>'w',
    'KS'=>'Knss',
    'KY'=>'Kntck',
    'LA'=>'Lsn',
    'ME'=>'Mn',
    'MH'=>'Mrshll slnds',
    'MD'=>'Mrlnd',
    'MA'=>'Msschstts',
    'MI'=>'Mchgn',
    'MN'=>'Mnnst',
    'MS'=>'Msssspp',
    'MO'=>'Mssr',
    'MT'=>'Mntn',
    'NE'=>'Nbrsk',
    'NV'=>'Nvd',
    'NH'=>'Nw Hmpshr',
    'NJ'=>'Nw Jrs',
    'NM'=>'Nw Mxc',
    'NY'=>'Nw rk',
    'NC'=>'Nrth Crln',
    'ND'=>'Nrth Dkt',
    'MP'=>'Nrthrn Mrn slnds',
    'OH'=>'h',
    'OK'=>'klhm',
    'OR'=>'rgn',
    'PW'=>'Pl',
    'PA'=>'Pnnslvn',
    'PR'=>'Prt Rc',
    'RI'=>'Rhd slnd',
    'SC'=>'Sth Crln',
    'SD'=>'Sth Dkt',
    'TN'=>'Tnnss',
    'TX'=>'Txs',
    'UT'=>'th',
    'VT'=>'Vrmnt',
    'VI'=>'Vrgn slnds',
    'VA'=>'Vrgn',
    'WA'=>'Wshngtn',
    'WV'=>'Wst Vrgn',
    'WI'=>'Wscnsn',
    'WY'=>'Wmng',
    'AE'=>'rmd Frcs frc \ Cnd \ rp \ Mddl st',
    'AA'=>'rmd Frcs mrc (xcpt Cnd)',
    'AP'=>'rmd Frcs Pcfc'
];

humbletiger commented on Nov 27, 2021

edited

Convert case insensitive long-form spelling into the abbreviation, or return original uppercase if no match (comedy not included).

function state($state_entry) {
	switch( strtolower($state_entry) ) {
		case "district of columbia": $state = "DC"; break;
		case "alaska": $state = "AK"; break;
		case "alabama": $state = "AL"; break;
		case "arkansas": $state = "AR"; break;
		case "arizona": $state = "AZ"; break;
		case "california": $state = "CA"; break;
		case "colorado": $state = "CO"; break;
		case "connecticut": $state = "CT"; break;
		case "delaware": $state = "DE"; break;
		case "florida": $state = "FL"; break;
		case "georgia": $state = "GA"; break;
		case "hawaii": $state = "HI"; break;
		case "iowa": $state = "IA"; break;
		case "idaho": $state = "ID"; break;
		case "illinois": $state = "IL"; break;
		case "indiana": $state = "IN"; break;
		case "kansas": $state = "KS"; break;
		case "kentucky": $state = "KY"; break;
		case "louisiana": $state = "LA"; break;
		case "massachusetts": $state = "MA"; break;
		case "maryland": $state = "MD"; break;
		case "maine": $state = "ME"; break;
		case "michigan": $state = "MI"; break;
		case "minnesota": $state = "MN"; break;
		case "missouri": $state = "MO"; break;
		case "mississippi": $state = "MS"; break;
		case "montana": $state = "MT"; break;
		case "north carolina": $state = "NC"; break;
		case "north dakota": $state = "ND"; break;
		case "nebraska": $state = "NE"; break;
		case "new hampshire": $state = "NH"; break;
		case "new jersey": $state = "NJ"; break;
		case "new mexico": $state = "NM"; break;
		case "nevada": $state = "NV"; break;
		case "new york": $state = "NY"; break;
		case "ohio": $state = "OH"; break;
		case "oklahoma": $state = "OK"; break;
		case "oregon": $state = "OR"; break;
		case "pennsylvania": $state = "PA"; break;
		case "rhode island": $state = "RI"; break;
		case "south carolina": $state = "SC"; break;
		case "south dakota": $state = "SD"; break;
		case "tennessee": $state = "TN"; break;
		case "texas": $state = "TX"; break;
		case "utah": $state = "UT"; break;
		case "virginia": $state = "VA"; break;
		case "vermont": $state = "VT"; break;
		case "washington": $state = "WA"; break;
		case "wisconsin": $state = "WI"; break;
		case "west virginia": $state = "WV"; break;
		case "wyoming": $state = "WY"; break;
		default: $state = $state_entry;
	}
	return strtoupper($state);
}

iamkeir commented on Mar 25

WHY IS EVERYONE SHOUTING

$stateNames = [
'AL' => 'Alabama', 
'AK' => 'Alaska', 
'AS' => 'American Samoa', 
'AZ' => 'Arizona', 
'AR' => 'Arkansas', 
'AE' => 'Armed Forces - Europe', 
'AP' => 'Armed Forces - Pacific', 
'AA' => 'Armed Forces - USA/Canada', 
'CA' => 'California', 
'CO' => 'Colorado', 
'CT' => 'Connecticut', 
'DE' => 'Delaware', 
'DC' => 'District of Columbia', 
'FM' => 'Federated States of Micronesia', 
'FL' => 'Florida', 
'GA' => 'Georgia', 
'GU' => 'Guam', 
'HI' => 'Hawaii', 
'ID' => 'Idaho', 
'IL' => 'Illinois', 
'IN' => 'Indiana', 
'IA' => 'Iowa', 
'KS' => 'Kansas', 
'KY' => 'Kentucky', 
'LA' => 'Louisiana', 
'ME' => 'Maine', 
'MH' => 'Marshall Islands', 
'MD' => 'Maryland', 
'MA' => 'Massachusetts', 
'MI' => 'Michigan', 
'MN' => 'Minnesota', 
'MS' => 'Mississippi', 
'MO' => 'Missouri', 
'MT' => 'Montana', 
'NE' => 'Nebraska', 
'NV' => 'Nevada', 
'NH' => 'New Hampshire', 
'NJ' => 'New Jersey', 
'NM' => 'New Mexico', 
'NY' => 'New York', 
'NC' => 'North Carolina', 
'ND' => 'North Dakota', 
'OH' => 'Ohio', 
'OK' => 'Oklahoma', 
'OR' => 'Oregon', 
'PA' => 'Pennsylvania', 
'PR' => 'Puerto Rico', 
'RI' => 'Rhode Island', 
'SC' => 'South Carolina', 
'SD' => 'South Dakota', 
'TN' => 'Tennessee', 
'TX' => 'Texas', 
'UT' => 'Utah', 
'VT' => 'Vermont', 
'VI' => 'Virgin Islands', 
'VA' => 'Virginia', 
'WA' => 'Washington', 
'WV' => 'West Virginia', 
'WI' => 'Wisconsin', 
'WY' => 'Wyoming', 
];

yomyyo commented on Mar 30

edited

Reverse reverse

$statesToAbbr = array(
  'Alaska' => 'AK',
  'Alabama' => 'AL',
  'Arkansas' => 'AR',
  'Arizona' => 'AZ',
  'California' => 'CA',
  'Colorado' => 'CO',
  'Connecticut' => 'CT',
  'Delaware' => 'DE',
  'Florida' => 'FL',
  'Georgia' => 'GA',
  'Hawaii' => 'HI',
  'Idaho' => 'ID',
  'Illinois' => 'IL',
  'Indiana' => 'IN',
  'Iowa' => 'IA',
  'Kentucky' => 'KY',
  'Louisiana' => 'LA',
  'Maine' => 'ME',
  'Maryland' => 'MD',
  'Massachusetts' => 'MA',
  'Michigan' => 'MI',
  'Minnesota' => 'MN',
  'Mississippi' => 'MS',
  'Missouri' => 'MO',
  'Montana' => 'MT',
  'Nebraska' => 'NE',
  'Nevada' => 'NV',
  'New Hampshire' => 'NH',
  'New Jersey' => 'NJ',
  'New Mexico' => 'NM',
  'New York' => 'NY',
  'North Carolina' => 'NC',
  'North Dakota' => 'ND',
  'Ohio' => 'OH',
  'Oklahoma' => 'OK',
  'Oregon' => 'OR',
  'Pennsylvania' => 'PA',
  'Rhode Island' => 'RI',
  'South Carolina' => 'SC',
  'South Dakota' => 'SD',
  'Tennessee' => 'TX',
  'Texas' => 'AK',
  'Utah' => 'UT',
  'Vermont' => 'VT',
  'Virginia' => 'VA',
  'Washington' => 'WA',
  'West Virginia' => 'WV',
  'Wisconsin' => 'WI',
  'Wyoming' => 'WY',
);

A PHP array of state names and abbreviations but every time there's an 'a' I insert the next lyric to All-Star by Smash Mouth

<?php

/* From https://pe.usps.com/text/pub28/28apb.htm && https://www.google.com/search?q=all+star+lyrics */

$us_state_all_star_names = array(
	'AsomebodyL'=>'AonceLAtoldBAmeMAthe',
	'AworldK'=>'AisLAgonnaSKAroll',
	'AmeS'=>'AiMERICAaintN SAtheMOAsharpest',
	'AtoolZ'=>'AinRIZONAthe',
	'AshedR'=>'AsheRKAwasNSAlookingS',
	'CAkind'=>'CAofLIFORNIAdumb',
	'CO'=>'COLORAwithDO',
	'CT'=>'CONNECTICUT',
	'DE'=>'DELAherWAfingerRE',
	'DC'=>'DISTRICT OF COLUMBIAand',
	'FM'=>'FEDERAherTED STAthumbTES OF MICRONESIAin',
	'FL'=>'FLORIDAthe',
	'GAshape'=>'GEORGIAof',
	'GU'=>'GUAanM GU',
	'HI'=>'HA"L"WAonII',
	'ID'=>'IDAherHO',
	'IL'=>'ILLINOIS',
	'IN'=>'INDIAforeheadNAwell',
	'IAthe'=>'IOWAyears',
	'KS'=>'KAstartNSAcomingS',
	'KY'=>'KENTUCKY',
	'LAand'=>'LOUISIAtheyNAdont',
	'ME'=>'MAstopINE',
	'MH'=>'MAcomingRSHAfedLL ISLAtoNDS',
	'MD'=>'MAtheRYLArulesND',
	'MAand'=>'MAiSSAhitCHUSETTS',
	'MI'=>'MICHIGAtheN',
	'MN'=>'MINNESOTAground',
	'MS'=>'MISSISSIPPI',
	'MO'=>'MISSOURI',
	'MT'=>'MONTArunningNAdidnt',
	'NE'=>'NEBRAmakeSKAsense',
	'NV'=>'NEVAnotDAto',
	'NH'=>'NEW HAliveMPSHIRE',
	'NJ'=>'NEW JERSEY',
	'NM'=>'NEW MEXICO',
	'NY'=>'NEW YORK',
	'NC'=>'NORTH CAforROLINAfun',
	'ND'=>'NORTH DAyourKOTAbrain',
	'MP'=>'NORTHERN MAgetsRIAsmartNAbut ISLAyourNDS',
	'OH'=>'OHIO',
	'OK'=>'OKLAheadHOMAgets',
	'OR'=>'OREGON',
	'PW'=>'PAdumbLAsoU',
	'PAmuch'=>'PENNSYLVAtoNIAdo',
	'PR'=>'PUERTO RICO',
	'RI'=>'RHODE ISLAsoND',
	'SC'=>'SOUTH CAmuchROLINAto',
	'SD'=>'SOUTH DAseeKOTAso',
	'TN'=>'TENNESSEE',
	'TX'=>'TEXAwhatsS',
	'UT'=>'UTAwrongH',
	'VT'=>'VERMONT',
	'VI'=>'VIRGIN ISLAwithNDS',
	'VAtaking'=>'VIRGINIAthe',
	'WAback'=>'WAstreetsSHINGTON',
	'WV'=>'WEST VIRGINIAyoull',
	'WI'=>'WISCONSIN',
	'WY'=>'WYOMING',
	'AneverE'=>'AknowRMED FORCES AifFRICAyou \ CAdontNAgoDAyoull \ EUROPE \ MIDDLE EAneverST',
	'AshineAif'=>'AyouRMED FORCES AdontMERICAglow (EXCEPT CAheyNAnowDAyoure)',
	'AanP'=>'AallRMED FORCES PAstarCIFIC'
);

?>

This is not accurate


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK