note 46599 deleted from control-structures.alternative-syntax by curt

From: Date: Sun, 17 Oct 2004 05:10:42 +0000
Subject: note 46599 deleted from control-structures.alternative-syntax by curt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-78685@lists.php.net to get a copy of this message
Note Submitter: dev at kiwicore dot org ---- I'd like to further explain something that had me confused for a while, as I wasn't reading the examples very carefully. When using the short if else syntax there are two styles: return (empty($value)) ? false : $value; is just like: if(empty($value)) return false; else return $value (and remember that if you're just executing one statement per branch, no brackets are required) However the second "inline" style is what's being used in the nested examples below and the difference is that: $string = 'The var Value is equal to '.(empty($value) ? 'empty' : $value); the entire statement is inside of the outer brackets. Also note that while the first style can only be used in a normal block of code, you can place the inline style ANYWHERE, when calling a function, creating a foreach loop, anywhere a string or variable would normally go. So the following is valid perfectly valid: <?php foreach(explode(':',(count($a)>3?$small:$big)) as $item) echo ($item == 3) ? 'three' : 'not three' ; ?> ---- Reason: useless note

« previous php.notes (#78685) next »