您可以始终使用( <condition> ? <value if true> : <value if false> )语法(它称为三元算子 - 感谢马克为我重新采矿:) ).如果<condition>为真,则该语句将被计算为<value if true>..如果没有,它将被评估为<value if false>例如:$fourteen = 14;$twelve = 12;echo "Fourteen is ".($fourteen > $twelve ? "more than" : "not more than")." twelve";这与:$fourteen = 14;$twelve = 12;if($fourteen > 12) {
echo "Fourteen is more than twelve";}else{
echo "Fourteen is not more than twelve";}