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? 🙂
That is actually the correct code. Instead of
||, you can also useor(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 == binto brackets:($a == b)to avoid funny situations in complexifstatements.