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:

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.




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>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to