DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

USA States List As A PHP Array

12.29.2005
| 66093 views |
  • submit to reddit
        An array list for use with PHP functions that create an HTML Select List or other structure.

$state_list = array('AL'=>"Alabama",  
			'AK'=>"Alaska",  
			'AZ'=>"Arizona",  
			'AR'=>"Arkansas",  
			'CA'=>"California",  
			'CO'=>"Colorado",  
			'CT'=>"Connecticut",  
			'DE'=>"Delaware",  
			'DC'=>"District Of Columbia",  
			'FL'=>"Florida",  
			'GA'=>"Georgia",  
			'HI'=>"Hawaii",  
			'ID'=>"Idaho",  
			'IL'=>"Illinois",  
			'IN'=>"Indiana",  
			'IA'=>"Iowa",  
			'KS'=>"Kansas",  
			'KY'=>"Kentucky",  
			'LA'=>"Louisiana",  
			'ME'=>"Maine",  
			'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",  
			'RI'=>"Rhode Island",  
			'SC'=>"South Carolina",  
			'SD'=>"South Dakota",
			'TN'=>"Tennessee",  
			'TX'=>"Texas",  
			'UT'=>"Utah",  
			'VT'=>"Vermont",  
			'VA'=>"Virginia",  
			'WA'=>"Washington",  
			'WV'=>"West Virginia",  
			'WI'=>"Wisconsin",  
			'WY'=>"Wyoming");
    

Comments

Patrick Thomas replied on Thu, 2010/06/10 - 11:11am

@mchollan or you could just flip the index with the following $state_list = array_combine(array_values($state_list), $state_list);

Snippets Manager replied on Thu, 2011/07/14 - 9:32am

Thanks TheldeaMan, I needed the opposite so I thought I would post it here as well: Indexed by the fullname lowercased. $state_list = array ('alabama'=>"AL", 'Alaska'=>"AK", 'Arizona'=>"AZ", 'Arkansas'=>"AR", 'California'=>"CA", 'Colorado'=>"CO", 'Connecticut'=>"CT", 'Delaware'=>"DE", 'District Of Columbia'=>"DC", '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") technomixx.com

Snippets Manager replied on Thu, 2011/07/14 - 9:32am

$state_list = array('AL'=>"Alabama", 'AK'=>"Alaska", 'AZ'=>"Arizona", 'AR'=>"Arkansas", 'CA'=>"California", 'CO'=>"Colorado", 'CT'=>"Connecticut", 'DE'=>"Delaware", 'DC'=>"District Of Columbia", 'FL'=>"Florida", 'GA'=>"Georgia", 'HI'=>"Hawaii", 'ID'=>"Idaho", 'IL'=>"Illinois", 'IN'=>"Indiana", 'IA'=>"Iowa", 'KS'=>"Kansas", 'KY'=>"Kentucky", 'LA'=>"Louisiana", 'ME'=>"Maine", '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", 'RI'=>"Rhode Island", 'SC'=>"South Carolina", 'SD'=>"South Dakota", 'TN'=>"Tennessee", 'TX'=>"Texas", 'UT'=>"Utah", 'VT'=>"Vermont", 'VA'=>"Virginia", 'WA'=>"Washington", 'WV'=>"West Virginia", 'WI'=>"Wisconsin", 'WY'=>"Wyoming"); Celebrities

Mikhail Kornienko replied on Sat, 2009/12/12 - 10:22pm

Some lesser states were missing, so here's the list of all the states: $state_list = array('ALABAMA'=>"AL", 'ALASKA'=>"AK", 'AMERICAN SAMOA'=>"AS", 'ARIZONA'=>"AZ", 'ARKANSAS'=>"AR", 'CALIFORNIA'=>"CA", 'COLORADO'=>"CO", 'CONNECTICUT'=>"CT", 'DELAWARE'=>"DE", 'DISTRICT OF COLUMBIA'=>"DC", "FEDERATED STATES OF MICRONESIA"=>"FM", 'FLORIDA'=>"FL", 'GEORGIA'=>"GA", 'GUAM' => "GU", 'HAWAII'=>"HI", 'IDAHO'=>"ID", 'ILLINOIS'=>"IL", 'INDIANA'=>"IN", 'IOWA'=>"IA", 'KANSAS'=>"KS", 'KENTUCKY'=>"KY", 'LOUISIANA'=>"LA", 'MAINE'=>"ME", 'MARSHALL ISLANDS'=>"MH", '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", "NORTHERN MARIANA ISLANDS"=>"MP", 'OHIO'=>"OH", 'OKLAHOMA'=>"OK", 'OREGON'=>"OR", "PALAU"=>"PW", 'PENNSYLVANIA'=>"PA", 'RHODE ISLAND'=>"RI", 'SOUTH CAROLINA'=>"SC", 'SOUTH DAKOTA'=>"SD", 'TENNESSEE'=>"TN", 'TEXAS'=>"TX", 'UTAH'=>"UT", 'VERMONT'=>"VT", 'VIRGIN ISLANDS' => "VI", 'VIRGINIA'=>"VA", 'WASHINGTON'=>"WA", 'WEST VIRGINIA'=>"WV", 'WISCONSIN'=>"WI", 'WYOMING'=>"WY");

Snippets Manager replied on Tue, 2009/04/07 - 8:16pm

Serious thanks from someone who uses this code snipped a bit too often.

Snippets Manager replied on Wed, 2009/03/18 - 6:40pm

Thanks TheldeaMan, I needed the opposite so I thought I would post it here as well: Indexed by the fullname lowercased. $state_list = array ('alabama'=>"AL", 'Alaska'=>"AK", 'Arizona'=>"AZ", 'Arkansas'=>"AR", 'California'=>"CA", 'Colorado'=>"CO", 'Connecticut'=>"CT", 'Delaware'=>"DE", 'District Of Columbia'=>"DC", '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")