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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
webmandman
Forum Newbie
Posts: 1
Joined: Wed Nov 22, 2006 5:42 pm

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

Post 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!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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";
Post Reply