Generate Select Box


/ Published in: PHP
Save to your folder(s)

Use this to generate a select box


Copy this code and paste it in your HTML
  1. function generate_select($values,$selected,$usekey=''){
  2. foreach ($values as $key=>$data){
  3. if(!empty($usekey)){$option_value = $key;}
  4. else{$option_value = $data;}
  5. if($selected == $option_value){echo "<option value = '$option_value' selected>$data</option>";}
  6. else{
  7. echo "<option value = '$option_value'>$data</option>";
  8. }
  9.  
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.