开发者

php if statement with one of two conditions if( a < b) or (b=0)

I have some huge blocks of code and I would like to avoid using elseif so th开发者_运维知识库e question is : Is it possible to construct an IF function with two possibilities in the same statement ? something like

  if( a < b) or (b=0)
{
statement
}


if( ($a < $b) || ($b==0) )
{
     //do something
}

or even better

if( ($a < $b) || (0==$b) )
{
     //do something
}

so you don't accidentally assign 0 to $b.


if( ($a<$b) OR ($b == 0) )
{
  //do something
}

Parenthesis in this case are not necessary, just added for clarity.


($a < $b ? 'a is smaller' : 'a equals or is greater');

Quick and easy, but not easily to maintain (personal opinion).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜