I have this code which works fine if the target variable is a single value
Assumption is $bank_country is a single value such as Brazil, there are no issue
<select class="form-control" multiple="1" name="country[]"> <option<? echo ($bank_country == 'Albania') ? ' selected="selected"' : ''; ?> value="Albania">Albania</option> <option<? echo ($bank_country == 'Algeria') ? ' selected="selected"' : '';?> value="Algeria">Algeria</option> <option<? echo ($bank_country == 'American Samoa') ? ' selected="selected"' : '';?> value="American Samoa">American Samoa</option> <option<? echo ($bank_country == 'Andorra') ? ' selected="selected"' : '';?> value="Andorra">Andorra</option> <option<? echo ($bank_country == 'Angola') ? ' selected="selected"' : '';?> value="Angola">Angola</option> However as my value is in multiple, it could be happen this way
Brazil*Germany*Spain whereby I have this code
if(strstr($bank_country,"*")) { $country_arr = explode("*",$bank_country); foreach($country_arr as $cca) { //code to echo out country with select on country that match } } How do I echo out my country when it have multiple value and it could have Brazil echo out with selected="selected" , so do Germany and Spain.
I been thinking for a while and got no idea how to append to my code to make it do Multiple if condition on this country before do a echo out with selected="selected"
Thanks for helping!!
<select>? Like the code provided?$all_countries = array('Albania', 'Algeria', 'American Samoa'); foreach ($all_countries as $country) { echo "<option value='$country' selected='" . ($country === $bank_country ? 'selected' : '') . "' >$country</option> }?