Re: Control Structure Syntax Question
| From: | Justin Patrin | Date: | Wed, 10 Mar 2004 00:22:39 +0000 |
| Subject: | Re: Control Structure Syntax Question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-179959@lists.php.net to get a copy of this message | ||
Ahbaid Gaffoor wrote:
Yeah, but if my code is less readable, my job security goes up ;) (Kidding) Thanks for all your help folks, that's what I needed. regards Ahbaid Richard Davey wrote:Before this thread dies, I'd like to clarify something. This syntax is mostly for inline ifs as what it does is return a value. For example: $apples = 2; echo 'There are '.$apples.' apple'.($apples == 1 ? '' : 's').'.'; In this case, it returns a string which is then echoed. This *could* be used in place of a normal if, but there is probably an added overhead as the value of the last statement is returned. Also, you *must* have an else when you use this syntax (even if it does nothing), it cannot be used for a simple if. -- paperCrane <Justin Patrin>Hello Ahbaid, Tuesday, March 9, 2004, 11:42:21 PM, you wrote: AG> Someone had posted a tip for using an abbreviated form of an if.. else AG> structure... AG> It looked something like: AG> $x : action1 : action2; $x ? xxx : xxx But it makes your code less readable IMHO and offers no tangible benefit whatsoever.