我正在构建一个菜单,我希望它由用户级别控制。我有一个与要显示的链接相呼应的 if 语句。但是,我不想显示整个子菜单,而是想将其分解为更多 if 语句。我该怎么做呢?
如果我没有任何意义,这是我的代码:
<?php
if (!isset($logged)) {
echo "";
} else {
echo "<li><a href=\"#\">Useful Info</a>
<ul>
<li><a href=\"offices.php\">Directory</a></li>"
if ($metric == "admins" || $metric == "management" || $metric == "executives" || $metric == "god") {
echo
"<li><a href=\"#\">Services Sub Menu 2</a></li>"
}
"<li><a href=\"about.php\">About</a></li>
<li><a href=\"#\">Services Sub Menu 4</a></li>
</ul>
</li>";
}
?>
这是我回答后的代码:
<?php
if (!isset($logged)) {
echo "";
} else {
echo "<li><a href=\"#\">Useful Info</a>
<ul>
<li><a href=\"offices.php\">Directory</a></li>";
if ($metric == "admins" || $metric == "management" || $metric == "executives" || $metric == "god") {
echo
"<li><a href=\"#\">Services Sub Menu 2</a></li>";
}
else {
echo "";
}
"<li><a href=\"about.php\">About</a></li>
<li><a href=\"#\">Services Sub Menu 4</a></li>
</ul>
</li>";
}
?>