如果条件为真,则返回PHP

如果条件为真,则返回PHP,php,Php,我有以下PHP代码: $supplier = $line[2]; if ($supplier == "supplier") { } else { Header("Location: premium.php"); } 现在我希望PHP代码中包含$supplier==“demo”,如下所示: $supplier = $line[2]; if ($supplier == "supplier" && $supplier == "demo") { } else { Header("Loc

我有以下PHP代码:

$supplier = $line[2];
if ($supplier == "supplier")
{
} else {
Header("Location: premium.php");
}
现在我希望PHP代码中包含$supplier==“demo”,如下所示:

$supplier = $line[2];
if ($supplier == "supplier" && $supplier == "demo")
{
} else {
Header("Location: premium.php");
}
但后一种代码对任何一种都不起作用。。。我的意思是,如果$supplier等于“supplier”或“demo”之外的其他内容,那么它仍然会绕过它。它只对第一个有效

我怎么安排呢?

排队
if($supplier==“supplier”和&$supplier==“demo”)

毫无意义<代码> $供货商< /代码>不能在条件语句的中间改变,因此永远不会是真的。您可能正在查找
|
(或)

线路
if($supplier==“supplier”和&$supplier==“demo”)

毫无意义<代码> $供货商< /代码>不能在条件语句的中间改变,因此永远不会是真的。您可能正在查找
|
(或)

“&&”表示:两个连接的语句都必须为真! “| |”的意思是:其中一个陈述必须是真的

您的构造没有意义,因为您说过$supplier必须是“demo”和“supplier”,这永远不会是真的,因为$var只能有一个值

错:

if ($supplier == "supplier" && $supplier == "demo") // AND would also work
对:

if ($supplier == "supplier" || $supplier == "demo") // OR would also work
“&&”表示:两个连接的语句都必须为真! “| |”的意思是:其中一个陈述必须是真的

您的构造没有意义,因为您说过$supplier必须是“demo”和“supplier”,这永远不会是真的,因为$var只能有一个值

错:

if ($supplier == "supplier" && $supplier == "demo") // AND would also work
对:

if ($supplier == "supplier" || $supplier == "demo") // OR would also work
不可能是真的,因为$supplier不可能同时是两个。您需要一个或多个类似的:

if ($supplier == "supplier" || $supplier == "demo")
不可能是真的,因为$supplier不可能同时是两个。您需要一个或多个类似的:

if ($supplier == "supplier" || $supplier == "demo")

当然要抓住这个机会去理解别人提到的
&&
| |
的含义,但是如果“或”确实是你想要的逻辑,在这种情况下,我建议:

if ( in_array( $supplier, array( "supplier", "demo" ) ) )

当然要抓住这个机会去理解别人提到的
&&
| |
的含义,但是如果“或”确实是你想要的逻辑,在这种情况下,我建议:

if ( in_array( $supplier, array( "supplier", "demo" ) ) )

而不是&&你的意思是?谢谢&&means,一个$supplier不能同时是两个不同的东西,试着用| |替换&&means,这意味着orthanks@hackattack它起作用了@PiedpiperMalta你最好再去看看,而不是&&你是说?谢谢&&means,一个$supplier不能同时是两个不同的东西,试着用| |替换&&means,这意味着orthanks@hackattack它起作用了@PiedpiperMalta你最好再去看看