Created
June 15, 2012 07:37
-
-
Save corsonr/2935229 to your computer and use it in GitHub Desktop.
Nice selected() fucntion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Testing the values with if() --> | |
<select name="options[foo]"> | |
<option value="1" <?php if ( $options['foo'] == 1 ) echo 'selected="selected"'; ?>>1</option> | |
<option value="2" <?php if ( $options['foo'] == 2 ) echo 'selected="selected"'; ?>>2</option> | |
<option value="3" <?php if ( $options['foo'] == 3 ) echo 'selected="selected"'; ?>>3</option> | |
</select> | |
<!-- Using selected() instead --> | |
<select name="options[foo]"> | |
<option value="1" <?php selected( $options['foo'], 1 ); ?>>1</option> | |
<option value="2" <?php selected( $options['foo'], 2 ); ?>>2</option> | |
<option value="3" <?php selected( $options['foo'], 3 ); ?>>3</option> | |
</select> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment