Php if语句的单独子句?

Php if语句的单独子句?,php,if-statement,clause,Php,If Statement,Clause,有没有办法在if()语句中包含多个子句 例如: if( ($username=='textUser' && $role=='admin') || ($admin=='yes')) { // If the username AND role are set to admin OR if the admin is set to 'yes' } else { // Neither clauses of the if statement are true } 也许这实际

有没有办法在
if()
语句中包含多个子句

例如:

if( ($username=='textUser' && $role=='admin') || ($admin=='yes'))
{
    // If the username AND role are set to admin OR if the admin is set to 'yes'
}
else
{
    // Neither clauses of the if statement are true
}

也许这实际上是正确的代码,我还没有试过——但如果没有,有人能告诉我怎么做吗?:)

这实际上是正确的代码。除了使用
| |
,您还可以使用
(尽管它们在以下方面略有不同,但与本案无关,但值得注意的是,cheers@Timothy。)


我倾向于将每一个条件
$a==b
放在括号中:
($a==b)
,以避免在复杂的
if
语句中出现有趣的情况。

@tarnfeld-将来,在询问代码是否正确之前,可能值得尝试一下您的代码。嗯,我不建议随意选择
|
,因为它们的意思都略有不同。它们都表示“或”,但操作的优先级不同。