note 25063 modified in control-structures by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Tue, 10 Sep 2002 19:00:14 +0000 |
| Subject: | note 25063 modified in control-structures by jmcastagnetto | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-36465@lists.php.net to get a copy of this message | ||
[Editor's note: It would be better practice to use the ternary operator as argument for the
"print" language construct, e.g.:
print ($foo == $bar) ? "The match" : "They don't match";
Same approach can be used for assignment.]
For short if-else's:
if ($foo == $bar) {
print "They match";
} else {
print "They don't match";
}
This can quickly be converted into:
($foo == $bar) ? print "They match" : print "They don't match";
This can be useful if the check's intention can be expressed in matter of a single function,
like this.
--was--
For short if-else's:
if ($foo == $bar) {
print "They match";
} else {
print "They don't match";
}
This can quickly be converted into:
($foo == $bar) ? print "They match" : print "They don't match";
This can be useful if the check's intention can be expressed in matter of a single function,
like this.
http://www.php.net/manual/en/control-structures.php