PHP: How can I determine if a variable has a value that is between two distinct constant values?

Gabriel Meono picture Gabriel Meono · Apr 14, 2011 · Viewed 145.3k times · Source

How can I determine using PHP code that, for example, I have a variable that has a value

  • between 1 and 10, or
  • between 20 and 40?

Answer

Daniel A. White picture Daniel A. White · Apr 14, 2011
if (($value > 1 && $value < 10) || ($value > 20 && $value < 40))