...

View Full Version : short code syntax



celestine
10-26-2004, 05:52 AM
can someone tells me what does this means?

$length = $len >= 0? $len: count($array);

thanks

fci
10-26-2004, 06:28 AM
it is the ternary operator. usually simplifies if-then's, but don't overuse it.

the example you posted is equivalent to this:


if ($len>=0) {
$length = $len;
} else {
$length = count($array);
}


some site with more info
http://www.totallyphp.co.uk/tutorials/using_if_else_ternary_operators.htm

trib4lmaniac
10-26-2004, 02:12 PM
If you start to use it, I think it looks more readable if you write it as

$length = ($len >= 0) ? $len : count($array);

celestine
10-27-2004, 03:38 AM
wow. thanks alot. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum