[英]How to use Php Comparison and Ternary Operators in this code?
I've been reading the documents and trying to make a piece of code work to no avail. 我一直在阅读文档,并试图使一段代码无效。 I'm wanting to check a radio input if the value matches the one in the database.
我想检查单选输入是否与数据库中的值匹配。 I'm posting the relevant piece of code.
我正在发布相关的代码。
Original if statement 原始if陈述
if(isset($_POST['radioValue'])){
if($prospectAnswer == $script[$getScriptAA]){
echo 'checked="checked';}}
What I have tried so far... 到目前为止我尝试过的...
$input .= ' <input
'.((isset($_POST['radioValue'])
&& ($prospectAnswer == $script[$getScriptAA])) ? 'checked="checked').'
type="radio"
name="sAnswer"
value="'.$script[$getScriptAA].'">
<span class="radiotext"> '.$script[$getScriptAA].'</span>';
Looks like your code is missing the 2nd part of the ternary, add : ''
after 'checked="checked"'
. 看起来您的代码缺少三元组的第二部分,请在
'checked="checked"'
之后添加: ''
'checked="checked"'
。
$input .= ' <input
'.(isset($_POST['radioValue']) && $prospectAnswer == $script[$getScriptAA] ? 'checked="checked"' : '').'
type="radio"
name="sAnswer"
value="'.$script[$getScriptAA].'">
<span class="radiotext"> '.$script[$getScriptAA].'</span>';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.