Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1178010
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: PHP

2015-02-01 19:35:17


  1. <?php
  2. /**
  3.  * 多数据源串行分页算法
  4.  * @param arr $arrSourceCount 数据源标识=>元素数量
  5.  * @param int $offset 起始位置
  6.  * @param int $length 长度
  7.  * @return arr 数据源标识=>array('offset'=>起始位置, 'length'=>长度)
  8.  * @author flynetcn
  9.  */
  10. function multiSerialPaging($arrSourceCount, $offset=0, $length=10)
  11. {
  12.     $start = 0;
  13.     $end = $offset + $length;
  14.     $scopeList = array();
  15.     foreach ($arrSourceCount as $k => $count) {
  16.         $start += $count;
  17.         if ($offset<$start && $offset>=$start-$count) {
  18.             $scopeList[$k] = array(
  19.                 'offset'=>$offset-($start-$count),
  20.             );
  21.             if ($end > $start) {
  22.                 $scopeList[$k]['length'] = $count - $scopeList[$k]['offset'];
  23.             }
  24.         }
  25.         if ($end<=$start && $end>$start-$count) {
  26.             if ($offset >= $start-$count) {
  27.                 $scopeList[$k]['length'] = $length;
  28.             } else {
  29.                 $scopeList[$k]['offset'] = 0;
  30.                 $scopeList[$k]['length'] = $length-($start-$count-$offset);
  31.             }
  32.         }
  33.         if ($start<$end && $start-$count>$offset) {
  34.             $scopeList[$k]['offset'] = 0;
  35.             $scopeList[$k]['length'] = $count;
  36.         }
  37.     }
  38.     return $scopeList;
  39. }

阅读(1372) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~