I have this code :
$genders = array('Male', 'Female');
foreach ( $genders as $gender ) {
echo '<option' . ( $rowMyBiodata['Gender'] == $gender ? ' selected' : '' ) . '>';
echo $gender;
echo '</option>';
}
and that code produce HTML code like this :
<option selected>Male</option>
<option>Female</option>
now, I want to add a value on each option so that output will be like this :
<option selected value='M'>Male</option>
<option value='F'>Female</option>
I think by changing the array into associative array can solve this problem :
$genders = array('M'=>'Male', 'F'=>'Female');
but how to get array's index so it can be used as value on the option tag?