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

时间:2016-04-01 05:52:47

标签: php laravel laravel-4

有没有办法在三元声明中做三元语句。例如

@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与给定值匹配。

4 个答案:

答案 0 :(得分:2)

您可以尝试这样的事情:

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

答案 1 :(得分:1)

试试这个

$foo = 1;
$bar = ($foo == 1) ? "1" : (($foo == 2)  ? "2" : "other");
echo $bar;

答案 2 :(得分:1)

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

答案 3 :(得分:-1)

    <div class="big-search-box"> 
    <form role="form" class=""> 
        <div class="input-group"> 
            <input type="text" placeholder="Input your search query..." class="form-control nrb input-lg"> 
            <div class="input-group-btn"> 
                <button data-toggle="dropdown" class="btn btn-primary dropdown-toggle btn-iconed btn-lg" type="button">
                    <i class="fa fa-file-text-alt"></i> <span>Search</span>
                </button> 
            </div> 
        </div> 
    </form> 
</div>