如何在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
热门推荐
6 薛之谦祝福语简短
10 生日祝福语男孩 简短独特
11 歌词祝福语高级文案简短
12 毕业祝福语简短给同学
13 高考毕业祝福语简短励志
14 恩师退休花束祝福语简短
15 开业经典祝福语简短
16 小年好的祝福语简短
17 牛年新年祝福语大全简短
18 幸福卡片祝福语英文简短