如何将isset和运算符用作一个三元语句


How to use isset and operators as one ternary statement

有没有一种方法可以在三元语句中执行三元语句。例如

@if (isset($checking))
<input type="radio" id="box" name="form" value="10"
{{$checking->myvalue == 10.0 ? 'checked' : ''}}/>
<label class="sister" for="boxwindow" title="myvalue_10" </label>
@else
<input type="radio" id="box" name="form" value="10"/>
<label class="sister" for="boxwindow" title="myvalue_10" </label>
@endif               

然而,我更喜欢它看起来像这样:

<input type="radio" id="box" name="form" value="10"
isset($checking->myvalue) == 10.0 ? 'checked' : ''}}/>
<label class="sister for="boxwindow" title="myvalue_10" </label>             

这样我就不必在else语句中重复代码了。这可能吗?

只是为了让你知道,我的目标是检查单选按钮,但前提是动态数字isset AND与给定值匹配。

你可以试试这样的东西:

{{ isset($checking->myvalue) && $checking->myvalue == 10 ? 'checked' : '' }}

试试这个

$foo = 1;
$bar = ($foo == 1) ? "1" : (($foo == 2)  ? "2" : "other");
echo $bar;
(isset($checking->myvalue) && $checking->myvalue == 10)?'checked' : '';
<?php echo isset($formData['employer_name'])?$formData['employer_name']:'_________________'; ?>