note 9796 deleted from Alternative syntax for control structures by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Sat, 25 Nov 2000 07:39:58 +0000 |
| Subject: | note 9796 deleted from Alternative syntax for control structures by jmcastagnetto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-8129@lists.php.net to get a copy of this message | ||
I vaguely remember seeing this somewhere, but it very well could've been in a Perl reference,
too.
There's an alternate if construct that I couldn't find in the manual here - it's very
useful if you want to test a condition mid-statement and don't want to break the statement for
the condition. Here's the syntax:
(condition) ? result if true : result if false
For example, let's say you're adding a record to a database; if the user gave their email
address, you want it to be added in parenthesis in the same field as the name. Assume $name already
contains the user's name, and $email may or may not contain the user's email address.
// Add email to name if present
$name = $name . ((isset($name)) ? (" (" . $email . ")") : "");