Home>Article>Backend Development> How to use php ternary operator

How to use php ternary operator

James Bond
James Bond Original
2019-09-20 11:53:15 8573browse

How to use php ternary operator

1. Ternary operator format: (expr1) ? (expr2) : (expr3)

2. Logical operation

How to use php ternary operator

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn