gpt4 book ai didi

PHP:三项验证比较

转载 作者:搜寻专家 更新时间:2023-10-31 21:46:17 25 4
gpt4 key购买 nike

我在主页上有 3 个特色产品面板,我正在为其编写一个 CMS 页面。我正在尝试验证这些项目。

它们是通过三个 <select> 选择的元素,featured1 , featured2featured3 .默认值为 <option value="0" selected>Select an element</option>

我需要验证 $_POST以确保用户没有为多个面板选择相同的产品。

我计算出每个 $_POST需要是 $_POST['featuredN'] > 0但我似乎无法找到处理 7 个潜在结果的合乎逻辑的方法。使用逻辑表,其中 1 是一个设定值。

1  2  3
-------
0 0 0
1 1 1
1 0 0
0 1 0
0 0 1
1 1 0
0 1 1

如果一个项目是 0,那么我不会更新它,但我希望用户能够在需要时更新单个项目。

我找不到一种合乎逻辑的方法来查看该项目是否不为 0,然后将其与另一个项目进行比较(如果该项目也不为 0)。

到目前为止,我的同事建议将值相加。哪个可以查看条件 1 0 0 0不满足。

我有一种模糊的感觉,某种形式的递归函数可能是有序的,但我无法完全让我的大脑帮助我解决这个问题!所以对于集体大脑! :)

最佳答案

为什么不使用一些简单的 ifs?

if($_POST['featured1'] != 0 && $_POST['featured1'] != $_POST['featured2'] && $_POST['featured1'] != $_POST['featured3']) {
// do something with featured1
}
if($_POST['featured2'] != 0 && $_POST['featured2'] != $_POST['featured1'] && $_POST['featured2'] != $_POST['featured3']) {
// do something with featured2
}
if($_POST['featured3'] != 0 && $_POST['featured3'] != $_POST['featured1'] && $_POST['featured3'] != $_POST['featured2']) {
// do something with featured3
}

关于PHP:三项验证比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3004619/

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