I have a key/value array with states info that looks like this (abreviated for space):
// states arrays
$states = array("AL"=>"Alabama [AL]",
"AK"=>"Alaska [AK]",
"AZ"=>"Arizona [AZ]",
"AR"=>"Arkansas [AR]",
"CA"=>"California [CA]",
"CO"=>"Colorado [CO]",
"CT"=>"Connecticut [CT]");
I am trying to loop through that array to spit out an HTML select form element but am running into trouble trying to access the key. I am using this PHP loop:
foreach($states as $k => $v){
$form .="
<option value=\"" . $states[$k] . "\"";
if ($sstate == $states[$k]){
$form .=" selected=\"selected\"";
}
$form .= ">" . $states[$v] . "</option>";
}
and I am getting HTML output that looks like this:
<select name="form_sc2">
<option value="Alabama [AL]"></option>
<option value="Alaska [AK]"></option>
<option value="Arizona [AZ]"></option>
<option value="Arkansas [AR]"></option>
<option value="California [CA]"></option>
<option value="Colorado [CO]"></option>
<option value="Connecticut [CT]"></option>
etc ...
The value is writing in where the key should be and the key is no where to be seen. I am stumped!
Any help is appreciated.