Rumah  >  Artikel  >  php教程  >  php array 分页

php array 分页

WBOY
WBOYasal
2016-06-06 19:44:131117semak imbas

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

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn