How to use php ternary operator

王林
Release: 2023-02-24 14:10:02
Original
8566 people have browsed it

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; ?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!