JON PANTAU
JON PANTAU

Reputation: 395

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 }

Upvotes: 0

Views: 611

Answers (4)

Ravi Hirani
Ravi Hirani

Reputation: 6539

In simple case, Ternary operator is best in practise.

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

Upvotes: 0

Ijas Ahamed N
Ijas Ahamed N

Reputation: 6110

You can use like this::

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

Upvotes: 0

devpro
devpro

Reputation: 16117

You can use like this:

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

Upvotes: 0

Hardik Solanki
Hardik Solanki

Reputation: 3195

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

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

Upvotes: 3

Related Questions