时时商务社区
标题:
PHP实现对数组分页处理实例详解
[打印本页]
作者:
xgnic
时间:
2018-2-14 05:28
本文实例讲述了PHP实现对数组分页处理方法。分享给大家供大家参考,具体如下:
最近用到了用数组数据分页,这里整理了一下,具体代码如下:
pageArray=$array;
$this->pageSize=$pageSize;
$this->current=$current;
}
/*通过数组进行初始化
*
* 数组为关联数组,参数索引为pageArray,pageSize,current
*
*/
function setArguments($arr){
if (is_array($arr)){
$this->pageArray=$arr['pageArray'];
$this->pageSize=$arr['pageSize'];
$this->current=$arr['current'];
}else{
return ;
}
}
//返回链接
function page(){
$_return=array();
/*calculator*/
$this->total=ceil(Count($this->pageArray)/$this->pageSize);
$this->prev=(($this->current-1)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;$ipageSize);$i++){
if($i >= $arrleng)break;
array_push($_return,$this->pageArray[$i]);
}
$pagearray["source"]=$_return;
$pagearray["links"]=$this->linkStyle(2);
return $pagearray;
}
//链接的样式
private function linkStyle($number=1){
$linkStyle='';
switch ($number){
case 1:
$linkStyle="[url=]first[/url] [url=]prev}\">prev[/url] [url=]next}\">next[/url] [url=]total}\">end[/url]";
break;
case 2:
$linkStyle="[url=]argumetsOther}\">首页[/url] [url=]prev}&{$this->argumetsOther}\">上一页[/url] [url=]next}&{$this->argumetsOther}\">下一页[/url] [url=]total}&{$this->argumetsOther}\">尾页[/url]";
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"];
*/
?>
更多关于PHP相关内容感兴趣的读者可查看本站专题:《
php+mysql数据库操作入门教程
》、《
php+mysqli数据库程序设计技巧总结
》、《
php面向对象程序设计入门教程
》、《
PHP数组(Array)操作技巧大全
》、《
php字符串(string)用法总结
》、《
PHP网络编程技巧总结
》及《
php常见数据库操作技巧汇总
》
希望本文所述对大家PHP程序设计有所帮助。
您可能感兴趣的文章:
php,ajax实现分页
php+mysql分页代码详解
php 分页原理详解
一个典型的PHP分页实例代码分享
php中长文章分页显示实现代码
精美漂亮的php分页类代码
ThinkPHP分页类使用详解
thinkphp实现数组分页示例
ThinkPHP使用心得分享-分页类Page的用法
PHP基于数组实现的分页函数实例
php简单实现数组分页的方法
php数组分页实现方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2