Jump to content

Umm what does this mean


desithugg

Recommended Posts

Okay well I've seen something like the following done many times in php,perl, javascript and more. But I still don't know what it really means. Can anyone tell me exactly what the statement means and how i can use it maybe.

$real_result = $boolean_result ? 1 : 0;

Link to comment
Share on other sites

Ternary operator. It's a shorthand for an IF-THEN-ELSE.

 

condition ? true_expression : false_expression

 

If the condition is true, evaluate the true_expression, otherwise evaluate the false_expression.

 

In your example:

 

$real_result = $boolean_result ? 1 : 0;

 

is equivalent to:

 

if ($boolean_result)
{
   $real_result = 1;
}else{
   $real_result = 0;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.