php数组分页
作者:会飞的
<?php
$array=array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20");
if(empty($_GET['page'])){
$page=1;
}else{
$page=$_GET["page"];
}
$r=page($array,"5",$page);
echo "<table><tr><td>bianhao</td></tr>";
foreach($r["source"] as $s){
echo "<tr><td>";
echo $s;
echo "</td></tr>";
}
echo "</table>";
echo "<br/>".$r["page"];
function page($array,$pagesize,$current){
$_return=array();
/*calculator*/
$total=ceil(Count($array)/$pagesize);
$prev=(($current-1)<=0 ? "1":($current-1));
$next=(($current+1)>=$total ? $total:$current+1);
$current=($current>($total)?($total):$current);
$start=($current-1)*$pagesize;
for($i=$start;$i<($start+$pagesize);$i++){
array_push($_return,$array[$i]);
}
$pagearray["source"]=$_return;
$pagearray["page"]="<a href="?page=1">first</a> <a href="?page={$prev}">prev</a> <a href="?page={$next}">next</a> <a href="?page={$total}">end</a>";
return $pagearray;
}
?>
猜你喜欢
您可能感兴趣的文章:
- 排序算法
- 40个技巧优化您的PHP代码
- Access to the requested object is only available from the local network.
- ISSET()、empty()、is_numeric()使用方法
- ob_get_contents() 函数的用法
- PHP OOP思想
- PHP XML Expat 解析器
- php 读取xml
- PHP 二分法查找数据
- PHP 发送邮件
- PHPer程序员评“一个PHP程序员的价值”
- php程序员容易犯的10种错误
- php代码中去除空格和其他特殊符号
- PHP导出一个txt文本文件
- PHP的foreach循环
- PHP的运行原理 内幕:PHP是如何显示“你好世界”的?
- php工程师面试题
- php工程师面试题2
- PHP面试题,PHP程序员面试题及答案