Home > php教程 > php手册 > php 使用array函数实现分页

php 使用array函数实现分页

WBOY
Release: 2016-06-13 09:14:39
Original
756 people have browsed it

php 使用array函数实现分页

 这里给大家分享的是一段php使用array()函数实现分页的代码,算是一种比较另类的分页思路,这里推荐给大家。

 

 

代码很简单,就不多废话了。

 

代码如下:


$array=array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20");//规定要分页的数组
$page= $_GET['page'];
$r = $this->page($array,5,$page);
print_r($r);
exit();
foreach($r["source"] as $s){
echo $s;
}
function page($array,$pagesize,$current){
$_return=array();
$total=ceil(Count($array)/$pagesize);//求总页数
$prev=(($current-1) $next=(($current+1)>=$total ? $total:$current+1);//确定下一页,如果当前页是最后一页,点击下页显示最后一页
$current=($current>($total)?($total):$current);//当前页如果大于总页数,当前页为最后一页
$start=($current-1)*$pagesize;//分页显示时,应该从多少条信息开始读取
for($i=$start;$i array_push($_return,$array[$i]);//将该显示的信息放入数组 $_return 中
}
$pagearray["source"]=$_return;
$pagearray["page"]="first \">prev next end";//分页样式可跟据需要调整
return $pagearray;
}

 

以上就是使用array函数实现分页的核心代码了,希望大家能够喜欢。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template