PHP实现对数组分页处理实例详解
发布:smiling 来源: PHP粉丝网 添加日期:2018-07-31 11:30:03 浏览: 评论:
- <?php
- 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;
- }
-
-
-
-
-
- functionsetArguments($arr){
- if(is_array($arr)){
- $this->pageArray=$arr['pageArray'];
- $this->pageSize=$arr['pageSize'];
- $this->current=$arr['current'];
- }else{
- return;
- }
- }
-
- functionpage(){
- $_return=array();
-
- $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++){<!--($start+$this--->
- 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="<a href="\"?page=1\"">first</a> <a href="\"?page={$this-">prev</a> <a href="\"?page={$this-">next</a> <a href="\"?page={$this-">end</a>";
- break;
- case2:
- $linkStyle="<a href="\"?page=1&{$this-">首页</a> <a href="\"?page={$this-">上一页</a> <a href="\"?page={$this-">下一页</a> <a href="\"?page={$this-">尾页</a>";
- break;
- }
- return$linkStyle;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
- ?>
分享到: