使用变量变量获取节标签,并使用php将其设置为新变量

问题描述 投票:0回答:1

我想问问这段代码是否可行。

$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>

谢谢!

php html variables tabs dynamic-variables
1个回答
2
投票

有可能,但您必须撤消作业。

$allowed_section = ['what', 'how', 'rules'];

if (isset($_GET['section']) && in_array($_GET['section'], $allowed_section)) {
    $$_GET['section'] = true;

} else {
    $section = $_GET['section'];
}
© www.soinside.com 2019 - 2024. All rights reserved.