MrFish Posted May 8, 2011 Share Posted May 8, 2011 For anyone who needs both the state and state symbol in an array. $states = array ( array("Alabama", "AL"), array("Alaska", "AK"), array("Arizona", "AZ"), array("Arkansas", "AR"), array("California", "CA"), array("Colorado", "CO"), array("Connecticut", "CT"), array("Delaware", "DE"), array("Florida", "FL"), array("Georgia", "GA"), array("Hawaii", "HI"), array("Idaho", "ID"), array("Illinois", "IL"), array("Indiana", "IN"), array("Iowa", "IA"), array("Kansas", "KS"), array("Kentucky", "KY"), array("Louisiana", "LA"), array("Maine", "ME"), array("Maryland", "MD"), array("Massachusetts", "MA"), array("Michigan", "MI"), array("Minnesota", "MN"), array("Mississippi", "MS"), array("Missouri", "MO"), array("Montana", "MT"), array("Nebraska", "NE"), array("Nevada", "NV"), array("New Hampshire", "NH"), array("New Jersey", "NJ"), array("New Mexico", "NM"), array("New York", "NY"), array("North Carolina", "NC"), array("North Dekota", "ND"), array("Ohio", "OH"), array("Oklahoma", "OK"), array("Oregon", "OR"), array("Pennsylvania", "PA"), array("Rhode Island", "RI"), array("South Carolina", "SC"), array("South Dakota", "SD"), array("Tennessee", "TN"), array("Texas", "TX"), array("Utah", "UT"), array("Vermont", "VT"), array("Virginia", "VI"), array("Washington", "WA"), array("West Virginia", "WV"), array("Wisconsin", "WI"), array("Wyoming", "WY") ) For example <select id="state" name="state"> <?php for($i = 0; $i < count($states); $i++) { $s = $states[$i][0]; $ss = $states[$i][1]; $selected = ""; if($region == $s) $selected = "SELECTED"; echo "<option value='$ss' $selected>$s</option>"; } ?></select> In my code $region is the stored state location of the user. With this I can get the users predefined location and automatically make it selected in this selection. Enjoy Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.