我想问问这段代码是否可行。
$allowed_section = ['what', 'how', 'rules'];
if (isset($_GET['section']) && in_array($_GET['section']), $allowed_section) {
$section = $_GET['section'];
} else {
$$_GET['section'] = "what";
}
如何在HTML中将$$ _ GET ['section']值声明为$ what或$ how或$ rules?有可能吗?
HTML示例:
<div class = "tab-content">
<div class="tab-pane fade show <?=($what)? "active" : ""; ?>"
id="what" role="tabpanel" aria-labelledby="what-tab"> ... </div>
<div class="tab-pane fade show <?=($how)? "active" : ""; ?>"
id="how" role="tabpanel" aria-labelledby="how-tab"> ... </div>
<div class="tab-pane fade show <?=($rules)? "active" : ""; ?>"
id="rules" role="tabpanel" aria-labelledby="rules-tab"> ... </div>
</div>
谢谢!
有可能,但您必须撤消作业。
$allowed_section = ['what', 'how', 'rules'];
if (isset($_GET['section']) && in_array($_GET['section'], $allowed_section)) {
$$_GET['section'] = true;
} else {
$section = $_GET['section'];
}