PHP: 如何检查一个数字是否在两个数字的集合之间

PHP: How to check if a number is between collection of two numbers

我有这样的代码

$count=15; // i manually initialising a value that not satisfying by folling condition
$low_limit=0;
$up_limit=10;
$num_pages=0;

(some loop) {

   if (($count >= $low_limit) && ($count <= $up_limit))
    {
        $num_pages=$numpages+1;
        echo $num_pages;
    }

   $low_limit=$up_limit+1;
   $up_limit=$up_limit+10;

} // loop ends

我的逻辑是

$count是一个变量 //这个值可以经常改变

$low_limit$up_limit 是取值范围 // 0-10 , 10-20 , 20-30 ,etc

$num_pages 是 return

的变量

1 if $low_limit= 0 and $up_limit= 10

2 if $low_limit= 11 and $up_limit= 20

3 if $low_limit= 21 and $up_limit= 30 and so on

这里的 $low_limit$up_limit 可以是任意数字(但是是 10 的倍数)。它可能高达 50,000。

some loop.?

中会有什么

我是如何构造这个程序的,我搜索了很多,但我只找到了检查范围内数字的程序。

如有任何帮助,我们将不胜感激。

由于上面的评论,它应该按预期工作:

$count = 34; // any number
$per_page = 10; // it's fixed number, but... 
$num_page = ceil($count / $per_page); // returns 4
$low_limit = ($num_page - 1) * $per_page; // returns 30
$up_limit = $num_page * $per_page; // returns 40

第 30 条记录和第 40 条记录之间是 11 条记录,而不是 10 条。

有更多方法可以解决这个问题:
1.比较< ... <=$low_limit < $count <= $up_limit
2.比较<= ... <$low_limit <= $count < $up_limit
3. 设置限制 1-10、11-20、21-30 等(上面第 4 行的 +1$low_limit
4. 设置限制 0-9、10-19、20-29 等(只需在上面第 5 行 -1$up_limit