? is the conditional operator or the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide; which value should be assigned to the variable.
| Syntax | Example | Explanation | |
| C/Java/Javascript/C# | conditionalExpression ? expression1 : expression2 | days= (February == ‘1’) ? 29 : 28; | If February is equal to 1 then days=29 otherwise 28 |
| C/Java/Javascript/C# | isMember ? “$4.00” : “$10.00”; | if is Member, assign the value $4.00 otherwise $10 | |
| PHP | If Condition is true ? Then value X : Otherwise value Y | $result = ($a > $b ) ? $a :$b; | If condition is true then assign a to result otheriwse b |
Leave a comment