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

后端 未结 13 636
傲寒
傲寒 2020-12-04 10:57

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

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 11:34

    You can try the following one-statement:

    if (($x-$min)*($x-$max) < 0)
    

    or:

    if (max(min($x, $max), $min) == $x)
    

提交回复
热议问题