首页 > php教程 > php手册 > 正文

php array 分页

WBOY
发布: 2016-06-06 19:44:13
原创
1113 人浏览过

$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; }

$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);//求总页数


$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;
}

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板