开发者

Separate clauses of an if statement?

开发者 https://www.devze.com 2022-12-18 23:33 出处:网络
Is there any way to have multiple clauses in an if() statement? For instance: if( ($username==\'textUser\' && $role==\'admin\') || ($admin==\'yes\'))

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开发者_Python百科 it - but if not, could anyone tell me how? :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消