我该如何删除/忽略&&&' IF声明中的条件

时间:2014-07-28 10:59:44

标签: php if-statement

假设我有三个POST变量

$one = $_POST['one'];
$two = $_POST['two'];
$three = $_POST['three'];

我还有另一个变量列表,可以与发布的值进行比较。

$four, $five, $six

所以如果发布变量的值为'All',我不需要将发布值与其他变量进行比较

例如:如果所有POST变量都没有“全部”值

if($one == $four && $two == $five && $three = $six)
{
//my code 
}

例如,当$_POST['two'] = 'All'时,条件将如下所示

if($one == $four && $three = $six)
{
//my code.
}

有没有简单的方法来实现这个目标?

2 个答案:

答案 0 :(得分:0)

尝试使用:

if(($one == 'one'||$one == 'All') && ($two == 'two'||$two == 'All') && ($three == 'three'||$three== 'All'))
{
//my code 
}

因为

A AND B = A whenever B is true

在这种情况下,如果括号中的表达式为真,则会(有效地)忽略它们。

答案 1 :(得分:0)

试试这个

if( ($one == $four || $one == 'All') && ($two == $five || $two == 'All') && ($three = $six || $three == 'All'))
{
//my code 
}

希望能给你想要的东西。