本文實(shí)例講述了php簡(jiǎn)單實(shí)現(xiàn)數(shù)組分頁的方法。分享給大家供大家參考,具體如下:
首先學(xué)東西 要多看手冊(cè)
用php自帶的函數(shù) 可以解決一些難解的問題
<?php
/**
* Created by JetBrains PhpStorm.
* User: Administrator
* Date: 13-6-11
* Time: 上午11:43
* To change this template use File | Settings | File Templates.
*/
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,20,21,22,23,24,25);
$page=$_GET['page']?(int)$_GET['page']:'0';
$size=5;
$pnum = ceil(count($array) / $size);
$newArray = array_slice($array,($page-1)*$size,$size);
foreach($newArray as $key=>$val)
{
echo "<a href=\"array1.php?catid=$key.html\" target=\"_blank\">$val</a>\n";
}
echo "<br/><br/><br/><br/>";
echo "<a href=?>第一頁</a>\n";
$str='';
for($i=1;$i<=$pnum-1;$i++)
{
echo "<a href=\"?page=$i\" target=\"_blank\"";
if($i==$page){echo "style='color:red;'";};
echo ">$i</a>\n\n";
}
echo "<a href=?page=$pnum>最后一頁</a>\n";
?>
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。