如何在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 宝宝100日简短祝福语
11 幽默小姐姐祝福语简短
12 祝福语年轻回复文案简短
13 小清新的祝福语简短
14 写字生日祝福语简短独特
15 祝福语同事离职英文简短
16 表达家人的祝福语简短
17 老公生日祝福语简短好看
18 祝福语对联文案简短大气