PHP实现对数组分页处理实例详解
发布:smiling 来源: PHP粉丝网 添加日期:2018-07-31 11:30:03 浏览: 评论:0
- <?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;
- }
- /*通过数组进行初始化
- *
- * 数组为关联数组,参数索引为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++){<!--($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;
- }
- }
- //调用的实例
- /*
- 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.'<br>';
- }
- echo $r["links"];
- */
- ?>
Tags: 组分 对数 实例
- 上一篇:php实现xml转换数组的方法示例
- 下一篇:php数组指针操作详解
相关文章
- ·php数组分组简单例子(2014-06-10)
- ·PHP数组分组排序程序代码(2014-06-17)
- ·php简单实现数组分页的方法(2019-08-12)
- ·php数组分页实现方法(2019-08-18)
- ·PHP中数组的分组排序实例(2021-01-31)
- ·PHP基于数组实现的分页函数实例(2021-04-06)
- ·php中json_decode返回数组或对象的实例(2014-06-29)
- ·php中计算二维数组平均值/分组平均值实例(2014-07-17)
- ·php常用的数组排序函数实例(2014-08-06)
- ·preg_replace()参数均为数组多次替换的实例理解(2014-09-13)
- ·php数组操作实例(2014-09-19)
- ·PHP数组操作的实例分析(2018-06-16)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)