gpt4 book ai didi

php - 从复选框中检索数据 - php

转载 作者:行者123 更新时间:2023-11-28 23:14:58 25 4
gpt4 key购买 nike

我有一个 Choice 列表,其中包含 4 种类型的文章。用户应该选择一个。现在该列表包含 45 篇文章,我将 choice list 更改为 checkBox list 以进行多项选择。

这遵循旧的 setter 函数:

 public function setNature($nature) {
$this->_nature = $nature;
if ($nature === 'Production') { $this->_nature='Production'; }
elseif ($nature === 'A'){ $this->_nature='A';}
elseif ($nature === 'B') {$this->_nature='B';}
else $this->_nature ='all';
}

如何在不写所有 45 种文章的情况下更改此 setter 函数来恢复数据?

最佳答案

您可以像这样自动查找允许的性质:

public function setNature($nature) {
$allowed_nature = ['A','B','Production'];
if(in_array($nature, $allowed_nature)){
$this->_nature = $nature;
}else{
$this->_nature = 'all';
}
}

唯一不利的一面是您需要将允许的性质存储在某个地方,在本例中是一个数组,但它也可以来自您的数据库。

根据你目前的信息,这就是我能做的!

关于php - 从复选框中检索数据 - php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44283268/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com