note 88791 added to language.operators.comparison

From: Date: Sun, 08 Feb 2009 02:37:20 +0000
Subject: note 88791 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-150374@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 96.21.63.216 ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/88791 Del: integrated -- https://master.php.net/note/delete/88791/integrated Del: useless -- https://master.php.net/note/delete/88791/useless Del: bad code -- https://master.php.net/note/delete/88791/bad+code Del: spam -- https://master.php.net/note/delete/88791/spam Del: non-english -- https://master.php.net/note/delete/88791/non-english Del: in docs -- https://master.php.net/note/delete/88791/in+docs Del: other reasons-- https://master.php.net/note/delete/88791 Reject -- https://master.php.net/note/reject/88791 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150374) next »