如何在PHP中使用三元运算符(?:)作为“ if / else”的简写?
语法如下-
$anyVariableName=yourCondition ? if condition becomes true then this will be executed: if condition becomes false then this gets executed;
示例
PHP代码如下
<!DOCTYPE html> <html> <body> <?php $value=100; $result=$value >=100 ? "Greater Than or Equal to 100":"Less Than 100"; echo $result; ?> </body> </html>
输出结果
这将产生以下输出
Greater Than or Equal to 100
热门推荐
10 广西考试祝福语结婚简短
11 猪年祝福语简短小孩
12 元旦祝福语送长辈简短
13 恭喜二宝祝福语简短
14 祝福语暖心话简短
15 国庆中秋祝福语简短兄弟
16 朋友订婚的祝福语简短
17 送弟弟中秋祝福语简短
18 爱生日祝福语简短独特