note 9796 added to Alternative syntax for control structures

From: Date: Fri, 24 Nov 2000 01:35:01 +0000
Subject: note 9796 added to Alternative syntax for control structures
Groups: php.notes 
Request: Send a blank email to php-notes+get-8043@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 . ")") : ""); http://www.php.net/manual/control-structures.alternative-syntax.php

« previous php.notes (#8043) next »