Page 1 of 1

is this is another form of the if statement? true: false;

Posted: Wed Nov 22, 2006 5:50 pm
by webmandman
thanks goes to the one with the answer or direction.

i've seen this before...i believe its another form of the if statement

myVar = isThisAllowed? true: false;

or something like that. can anyone clear this up for me...also whats the correct syntax for that?

happy thanksgiving!

Posted: Wed Nov 22, 2006 5:54 pm
by Burrito
that is called a 'ternary operator' and yes it works like an if statement.

Code: Select all

$something = FALSE;
$var = ($something ? "yes" : "no");
echo $var;
// no

//same as

if($something)
  $var = "yes";
else
  $var = "no";