简体   繁体   中英

php write statement IF ELSE condition interval/range

I have a problem in writing interval condition inside IF ELSE: This is my condition :

if(1<x<=30)
{ statement } 
else
{ statement }

If you want to check interval/range then you can do it using following:

if($x > 1 && $x <= 30){
  statement 
}else{
  statement       
}

You can use like this:

if(1 < $x AND $x <= 30)
    echo true;
else
    echo false;

You can use like this::

if(1<x && x<=30)
{ statement } 
else
{ statement }

在简单的情况下,三元运算符是最佳实践。

$result  = ($x > 1 && $x<=30) ? true : false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM