A US State Dropdown from PHP Array

A US state dropdown from a PHP array. We have also included an SQL state to insert into your database.

A PHP array for US states is a better cleaner option than adding all the option values into your HTML form. This is a working example of a dropdown for the US States from a PHP array. We also included the SQL statement if you would like to add it into a database instead. 

                //states array
		$states = array(
		    'DC'=>'District of Columbia',
		    'NH'=>'New Hampshire',
		    'NJ'=>'New Jersey',
		    'NM'=>'New Mexico',
		    'NY'=>'New York',
		    'NC'=>'North Carolina',
		    'ND'=>'North Dakota',
		    'RI'=>'Rhode Island',
		    'SC'=>'South Carolina',
		    'SD'=>'South Dakota',
		    'WV'=>'West Virginia',


This is the Foreach loop that display your states into your select options. 

	<?php foreach ($states as $key => $value) { ?>
	<option value="<?php echo $key; ?>"><?php echo $value; ?></option>
	<?php } ?>


View Demo

GitHub Files (SQL File)