Bnaya

HTML options list from php array

Jan 31st, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.32 KB | None | 0 0
  1. <?php
  2.  
  3. $data = array(
  4.     'opt1_value' => 'opt 1 title',
  5.     'opt2_value' => 'opt 2 title'
  6. );
  7.  
  8. $opts_str = '';
  9.  
  10. foreach($data as $opt_val => $opt_title) {
  11.     $opts_str .= '<option value="' . htmlspecialchars($opt_val) . '">"' . htmlspecialchars($opt_title) . '"</option>';
  12. }
  13.  
  14. ?>
  15.  
  16. <select>
  17. <?php echo $opts_str; ?>
  18. </select>
Advertisement
Add Comment
Please, Sign In to add comment