Click to See Complete Forum and Search --> : Dreamweaver MX uses ? and : to do what !?


rbeemsterboer
12-30-2002, 09:20 PM
Hi,

I'm tryed using Dreamweaver MX, but can anyone explain what does ? and : mean as a function, Because do not understand it :-)

$colname_Organisation = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['OrgId'] : addslashes($HTTP_GET_VARS['OrgId']);

Best Regards,
RIck Beemsterboer
Netherlands

128kb.com
12-30-2002, 10:08 PM
The ?: is the ternary operator for doing an if/else as an expression. For instance... an if/else block can't be used on the right side of an asignment operator or inside an expression.
$(is_array($var)) ? print "true\n" : print "false\n";
is analogus to:
if (is_array($var))
print "true\n";
else
print "false\n";

so you can say
$somevar = $(is_array($var)) ? true : false;
You can get really tricky with this inside complex expressions.
http://www.php.net/manual/en/language.operators.comparison.php

sanu
01-30-2003, 11:14 AM
couldn't get what actually ternary operater do and where is it suitable to use could you please explain it more