note 88791 deleted from language.operators.comparison by cmb
| From: | cmb@php.net | Date: | Sun, 11 Aug 2019 12:00:22 +0000 |
| Subject: | note 88791 deleted from language.operators.comparison by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211850@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
Here is some ternary trick I like to use for selecting a default value in a set of radio buttons.
This example assumes that a prior value was known and that we are offering a user the chance to edit
that prior value. If no prior value was actually known, no default value will be set.
<form>
<input type='radio' name='gender' value='m'
<?=($gender=='m')?"checked":""?>>Male
<input type='radio' name='gender' value='f'
<?=($gender=='f')?"checked":""?>>Female
</form>
When a "=" directly follows a "<?" (no space allowed in between -- the trick
does not work with "<?php"), the right side of the operand (here, the result of the
ternary operation) is printed out as text into the surrounding HTML code. If using
"<?php" form, you will need to do "<?php echo exp1?exp2:exp3 ?>"
instead.