Advertisement
xah

create_dropdown()

xah
Sep 29th, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. <?php
  2.  
  3. function create_dropdown($arr, $id){
  4.     echo '<label for="' . $id . '">';
  5.     echo '<select name="' . $id . '" id="' . $id .'">';
  6.  
  7.     if(isset($_POST[$id])){
  8.         $sel = 'selected = selected';}
  9.     else{ $sel = ''; }
  10.  
  11.     foreach($arr as $key => $val){
  12.         echo '<option value="' . $key . '"' . $sel . '>' . $val . '</option>';
  13.     }
  14.  
  15.     echo '</select>';
  16. }
  17.  
  18. /**$test = array('supplier' => 's', 'customer' => 'c');
  19.  
  20. create_dropdown($test, 'yolo');**/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement