Home>Article>Backend Development> How to use php ternary operator
1. Ternary operator format: (expr1) ? (expr2) : (expr3)
2. Logical operation
Note: Remember to add parentheses for addition and subtraction operations, otherwise the system may not recognize them sometimes.
Example:
"; if ($a > 10 && $b > 10) { echo "a和b都大于10" . "
"; } else { echo "a和b都小于10" . "
"; } //三目运算符: $c = 60; //如果$c与50相等,则$v的值为字符串:真值;否则,$v的值为字符串:假值。 $v = ($c == 50) ? "真值" : "假值"; echo $v; ?>
Recommended tutorial:PHP video tutorial
The above is the detailed content of How to use php ternary operator. For more information, please follow other related articles on the PHP Chinese website!