How to check if an integer is within a range of numbers in PHP?

Richard Peers picture Richard Peers · Jan 13, 2011 · Viewed 152.6k times · Source

How can I check if a given number is within a range of numbers?

Answer

Dancrumb picture Dancrumb · Jan 13, 2011

The expression:

 ($min <= $value) && ($value <= $max)

will be true if $value is between $min and $max, inclusively

See the PHP docs for more on comparison operators