note 102060 added to control-structures.if
| From: | ChristianL dot at osu1 dot php dot net | Date: | Tue, 25 Jan 2011 18:58:14 +0000 |
| Subject: | note 102060 added to control-structures.if | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176300@lists.php.net to get a copy of this message | ||
An other way for controls is the ternary operator (see Comparison Operators) that can be used as
follows:
<?php
$v = 1;
$r = (1 == $v) ? 'Yes' : 'No'; // $r is set to 'Yes'
$r = (3 == $v) ? 'Yes' : 'No'; // $r is set to 'No'
echo (1 == $v) ? 'Yes' : 'No'; // 'Yes' will be printed
// and since PHP 5.3
$v = 'My Value';
$r = ($v) ?: 'No Value'; // $r is set to 'My Value' because $v is evaluated to
TRUE
$v = '';
echo ($v) ?: 'No Value'; // 'No Value' will be printed because $v is evaluated
to FALSE
?>
Parentheses can be left out in all examples above.
----
Server IP: 69.147.83.197
Probable Submitter: 62.245.151.72
----
Manual Page -- http://www.php.net/manual/en/control-structures.if.php
Edit -- https://master.php.net/note/edit/102060
Del: integrated -- https://master.php.net/note/delete/102060/integrated
Del: useless -- https://master.php.net/note/delete/102060/useless
Del: bad code -- https://master.php.net/note/delete/102060/bad+code
Del: spam -- https://master.php.net/note/delete/102060/spam
Del: non-english -- https://master.php.net/note/delete/102060/non-english
Del: in docs -- https://master.php.net/note/delete/102060/in+docs
Del: other reasons-- https://master.php.net/note/delete/102060
Reject -- https://master.php.net/note/reject/102060
Search -- https://master.php.net/manage/user-notes.php