-1

Is there any way to have multiple clauses in an if() statement?

For instance:

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
}

Perhaps this is actually the correct code, i have no tried it - but if not, could anyone tell me how? :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
tarnfeld
  • 25,992
  • 41
  • 111
  • 146

1 Answers1

2

That is actually the correct code. Instead of ||, you can also use or (although they differ slightly in operator precedence, not relevant in the case at hand but worth noting, cheers @Timothy.)

I tend to put every condition $a == b into brackets: ($a == b) to avoid funny situations in complex if statements.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Well, I wouldn't recommend arbitrarily choosing `||` or `or` as each means something slightly different. They both mean "or", but the precedence of the operation is different. – Timothy May 09 '10 at 05:03