【问题标题】:An echo with has an ternary operator which echo's a span回声具有三元运算符,其回声是跨度
【发布时间】:2017-01-18 21:32:14
【问题描述】:

请看下面的代码,我已经尝试了一个小时,现在已经放弃并来到这里! 代码在回显结束时输出错误并且没有给出任何理由,我已将其缩小到三元运算符的问题,这是我第一次使用一个,所以我不确定问题出在哪里并且已经尝试了各种... 我是不是把三进制的格式弄错了?

代码检查一个值,如果该值存在,它会用刻度符号填充第一个单元格,并将变量的值回显到第二个单元格中。

echo "<table id='tbl' class='defecttable'>
    <tr>
        <th>Trailer:</th>
      <td>*Trailer*</td>  
        <th>Vehicle Mileage:</th>
        <td>*vehicle mileage*</td>        
    </tr>
    <tr>
        <th>Checks To Be Made</th>
        <th>Checked</th>
        <th>Reportable Defect?</th>
        <th>Defect Description</th>
    </tr>
    <tr>
        <th>Fuel/Oil Leaks:</th>
        <td><span class='glyphicon glyphicon-ok-circle'></span></td>  
        <td>".((isset($defect[fuel]) ? '<span class=glyphicon glyphicon-ok-circle"></span>': '')."</td>
        <td>".((isset($defect[fuel]) ? $defect[fuel]: '')."</td>       
    </tr>";

【问题讨论】:

    标签: php ternary-operator


    【解决方案1】:

    非常接近,但有几点需要注意。

    • 在每个issets 之前都有一个额外的(。
    • 您的意思是使用$defect['fuel'] 而不仅仅是$defect[fuel]?如果您不使用单引号或双引号将燃料括起来,则假定它是一个常数。

    结果:

    echo "<table id='tbl' class='defecttable'>
        <tr>
            <th>Trailer:</th>
          <td>*Trailer*</td>  
            <th>Vehicle Mileage:</th>
            <td>*vehicle mileage*</td>        
        </tr>
        <tr>
            <th>Checks To Be Made</th>
            <th>Checked</th>
            <th>Reportable Defect?</th>
            <th>Defect Description</th>
        </tr>
        <tr>
            <th>Fuel/Oil Leaks:</th>
            <td><span class='glyphicon glyphicon-ok-circle'></span></td>  
            <td>".(isset($defect['fuel']) ? '<span class=glyphicon glyphicon-ok-circle"></span>': '')."</td>
            <td>".(isset($defect['fuel']) ? $defect['fuel']: '')."</td>       
        </tr>";
    

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 1970-01-01
      • 2019-11-14
      • 2021-10-17
      • 2014-05-20
      • 1970-01-01
      • 2014-12-03
      • 2021-12-07
      • 1970-01-01
      相关资源
      最近更新 更多