desithugg Posted August 17, 2007 Share Posted August 17, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/65386-umm-what-does-this-mean/ Share on other sites More sharing options...
Aeglos Posted August 17, 2007 Share Posted August 17, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/65386-umm-what-does-this-mean/#findComment-326523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.