如何仅在满足 php 变量条件时显示我的选择选项值?

我有5个变量


$first ="first";

$second = "second";

$third = "third";

$fourth = "fourth";

$fifth = "fifth";

我在 html 中有这个选择选项


    <select name="e1" id="year" class="form-control" required="required">

      <option value="" selected="selected" style="background: #0356e8;color: white;">-  -</option>

      <option value="Attend To" style="background: #fd0303;color: white;">Attend To</option>

      <option value="Explore" style="background: #fd7803; color: white;">Explore</option> 

      <option value="Prompt" style="background: #fdd303; color: white;">Prompt</option>

      <option value="Unaided" style="background: #58d95e; color: white;">Unaided</option>

      <option value="Mastered" style="background: #12c4f9; color: white;">Mastered</option> 

      <option value="Not Applicable" style="background: grey; color: black;">Not Applicable</option>

    </select>

我怎样才能做到这一点,如果$first ="first"第一个选项不应该显示<option value="Attend To" style="background: #fd0303;color: white;">Attend To</option>......这个不应该显示。


如果$second = "second";那么第一个和第二个选项不应显示...


第三和第四也是如此。


一只萌萌小番薯
浏览 94回答 1
1回答

PIPIONE

为了回答你的问题:$variable='first / second ... '; // one variable如果您不想IF在同一页面中使用,可以在另一个页面中使用函数:function HowMuch($variable){if($variable=='first'){echo '&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <option value="Explore" style="background: #fd7803; color: white;">Explore</option>&nbsp;&nbsp; &nbsp; &nbsp; <option value="Prompt" style="background: #fdd303; color: white;">Prompt</option>&nbsp; &nbsp; &nbsp; <option value="Unaided" style="background: #58d95e; color: white;">Unaided</option>&nbsp; &nbsp; &nbsp; <option value="Mastered" style="background: #12c4f9; color: white;">Mastered</option>&nbsp;&nbsp; &nbsp; &nbsp; <option value="Not Applicable" style="background: grey; color: black;">Not Applicable</option>';}elseif($variable=='second '){echo '&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; <option value="Prompt" style="background: #fdd303; color: white;">Prompt</option>&nbsp; &nbsp; &nbsp; <option value="Unaided" style="background: #58d95e; color: white;">Unaided</option>&nbsp; &nbsp; &nbsp; <option value="Mastered" style="background: #12c4f9; color: white;">Mastered</option>&nbsp;&nbsp; &nbsp; &nbsp; <option value="Not Applicable" style="background: grey; color: black;">Not Applicable</option>';&nbsp;}}现在 select 所在的页面:<select name="e1" id="year" class="form-control" required="required">&nbsp; <option value="" selected="selected" style="background: #0356e8;color: white;">-&nbsp; -</option>&nbsp; &nbsp; &nbsp; HowMuch($variable); //variable contains first or second..&nbsp; &nbsp; </select>
打开App,查看更多内容
随时随地看视频慕课网APP