PHP - Store multiple select option into array and us the ID as array key -


i have selectbox option list multiple selection.

<select multiple="multiple" size="20" name="facilities[]">    <option id="idone" value="value one">value one</option>    <option id="idtwo" value="value two">value two</option>    <option id="idthree" value="value three">value three</option> </select> 

i have done php code can store value array on database, but.. want now, possible use id option key of array, when storing array sample below

array('idone'=>'value one', 'idtwo'=>value two, 'idthree'=>'value three') 

instead of array([0]=>'value one', [1]=>value two, [2]=>'value three') (that now).

any kind appreciate :)

sorry english bad.

by definition, value of option tags passed in post. there's couple of options here

first, need know values on other end , marry them up. more work potentially have list of values selected.

  $vals = array('idone'=>'value one', 'idtwo'=>'value two', 'idthree'=>'value three');   foreach($vals $key => $row) {        if(array_search($row, $_post['facilities']) === false) unset($vals[$key]);   } 

second use javascript , build list of text values selected , post (either via hidden field or using ajax). riskier since data in client's hands still doable.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -