最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP实现对数组分页处理实例详解
时间:2022-06-24 14:57:00 编辑:袖梨 来源:一聚教程网
代码如下 | 复制代码 |
classPaginationArray{ public$pageArray=array();//数组 public$pageSize=10;//每页显示记录数 public$current= 1;//当前页 private$total=0;//总页数 private$prev=0;//上一页 private$next=0;//下一页 public$argumetsOther='';//设置参数 function__construct($array=array(),$pageSize=10,$current=1){ $this->pageArray=$array; $this->pageSize=$pageSize; $this->current=$current; } /*通过数组进行初始化 * * 数组为关联数组,参数索引为pageArray,pageSize,current * */ functionsetArguments($arr){ if(is_array($arr)){ $this->pageArray=$arr['pageArray']; $this->pageSize=$arr['pageSize']; $this->current=$arr['current']; }else{ return; } } //返回链接 functionpage(){ $_return=array(); /*calculator*/ $this->total=ceil(Count($this->pageArray)/$this->pageSize); $this->prev=(($this->current-1)<= 0="" this-="">current-1)); $this->next=(($this->current+1)>=$this->total ?$this->total:$this->current+1); $current=($this->current>($this->total)?($this->total):$this->current); $start=($this->current-1)*$this->pageSize; $arrleng=count($this->pageArray); for($i=$start;$i<($start+$this->pageSize);$i++){ if($i>=$arrleng)break; array_push($_return,$this->pageArray[$i]); } $pagearray["source"]=$_return; $pagearray["links"]=$this->linkStyle(2); return$pagearray; } //链接的样式 privatefunctionlinkStyle($number=1){ $linkStyle=''; switch($number){ case1: $linkStyle="first prev next end"; break; case2: break; } return$linkStyle; } } //调用的实例 /* header('Content-Type: text/html;charset=utf-8'); $array=array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"); $page= isset($_GET['page'])? $_GET['page'] : 1 ; $arrayPage = new PaginationArray($array,"5",$page); $r = $arrayPage->page(); foreach($r["source"] as $s){ echo $s.' } echo $r["links"]; */ ?> |
相关文章
- 炉石传说兑换码大全 12-26
- 重返未来1999趋光性研究夜幕之外怎么玩 趋光性夜幕之外活动介绍 12-26
- 光遇12.26大蜡烛在哪里 光遇12月26日大蜡烛位置攻略 12-26
- 江南百景图金谷园怎么样 江南百景图金谷园建筑介绍 12-26
- 光遇12.26每日任务怎么做 光遇12月26日每日任务做法攻略 12-26
- 光遇12.26季节蜡烛在哪里 光遇12月26日季节蜡烛位置攻略 12-26