php echo语句php中的三元运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15283353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:58:46  来源:igfitidea点击:

ternary operator in echo statement php

php

提问by Andrew

I'm trying to implement an if else block into an echo statement with the tenary operator. I've followed it on if block inside echo statement.but I have no idea what's wrong with mine:

我正在尝试使用十元运算符将 if else 块实现到 echo 语句中。我已经在 echo 语句中的 if 块上进行了跟踪但我不知道我的有什么问题:

echo "<td><input type='checkbox' name='money' id='money'".(($money == 'yes')?'"checked"':" "."value='yes' /></td>";

回答by mellamokb

You are missing the closing parenthesis )to your expression:

您缺少)表达式的右括号:

...(($money == 'yes')?'"checked"':" ")."value='yes' /></td>";
                                     ^ add this

回答by Captain Payalytic

You have a bracket missing. Try:

您缺少一个支架。尝试:

echo "<td><input type='checkbox' name='money' id='money'".(($money == 'yes')?'"checked"':" ")."value='yes' /></td>";