dynamic dynamic - 1 year ago 96
PHP Question

How to check if an integer is within a range?

Is there a way to test a range without doing this redundant code:

if ($int>$min && $int<$max)


Like a function:

function testRange($int,$min,$max){
return ($min<$int && $int<$max);


if (testRange($int,$min,$max))


Does PHP have such built-in function? Or any other way to do it?

Answer Source

I don't think you'll get a better way than your function.

It is clean, easy to follow and understand, and returns the result of the condition (no return (...) ? true : false mess).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download