【发布时间】:2016-02-12 10:31:47
【问题描述】:
我试图弄清楚我应该如何构建 if/else 语句。
我理解基本的 if/esle 应该如下;
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
我不确定如何在我当前的语句中实现这个逻辑。我认为因为 php 混合在 html 中,这让我感到困惑:/
我确定这是非常错误的,但有人可以告诉我应该如何构建它吗?
<form role="form">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default <?php if ($status == '1' ) echo 'active btn-success' ; ?>">
<input type="radio" name="status" id="option1" value="1" autocomplete="off"> Active
</label>
<label class="btn btn-default <?php elseif ($status == '2' ) echo 'active btn-warning' ; ?>">
<input type="radio" name="status" id="option2" value="2" autocomplete="off"> Inactive
</label>
<label class="btn btn-default <?php else ($status == '3') echo 'active btn-danger' ; ?>">
<input type="radio" name="status" id="option3" value="3" autocomplete="off"> Not Found
</label>
</div>
</form>
我在 NetBeans 中看到的错误是;
语法错误:意外 elseif
我可以或应该只在每个标签上使用 if 语句吗?
【问题讨论】:
-
为什么
elseif&else。在每个标签中使用if。 -
不完全确定,但您可能想在 if / elseif / else 语句中使用开/关括号,它可能会解决您的错误。
标签: php html if-statement