php - 使用变量变量获取部分选项卡,并使用 php 将其设置为新变量
问题描述
我想问一下这段代码是否可行。
$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'];
}
推荐阅读
- c# - 创建 SQLite 表 Xamarin 表单
- angularjs - '角度未定义'
- maven - Maven Surefire 仅“默认测试”运行自定义执行被忽略
- java - 如何从 Java 访问 COM 自动化 DLL?
- apache-spark - spark如何与集群配置一起工作?
- javascript - 单击键/按钮时如何播放每个声音?
- hadoop - 结构中的 hive 处理时间戳列的错误?
- computer-vision - 我可以微调像 Resnet 和 Vgg19 这样的预训练分类 CNN 来预测图像中的某些角度吗?
- ruby - 我如何知道地理编码器结果是否只是城市名称的匹配项?
- java - Java:泛型:从泛型方法获取对象类型 T 并访问其方法