Advertisement
amereservant

Show States

Aug 17th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2.  
  3. function show_states_select()
  4. {
  5.     global $current_user;
  6.    
  7.     $states = array(
  8.         array(
  9.             'abbr'      => 'AR',
  10.             'fullname'  => 'Arkansas'
  11.         ),
  12.         array(
  13.             'abbr'      => 'TX',
  14.             'fullname'  => 'Texas'
  15.         )
  16.     );
  17.    
  18.     $select = "<select name=\"my-states\">\n%s</select>\n";
  19.     $format = "<option value=\"%s\"%s>%s</option>\n";
  20.     $opts   = '';
  21.    
  22.     for($i=0; $i<count($states); $i++)
  23.     {
  24.         $opts .= sprintf($format, $states[$i]['abbr'], selected($states[$i]['abbr'], $current_user->State),
  25.             $states[$i]['fullname']);
  26.     }
  27.     printf($select, $opts);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement