A simple way to implement array paging in php_php skills

WBOY
Release: 2016-05-16 19:53:29
Original
1649 people have browsed it

The example in this article describes how to simply implement array paging in PHP. Share it with everyone for your reference, the details are as follows:

To learn something first, read more manuals
Use the functions that come with PHP to solve some difficult problems

<&#63;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']&#63;(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&#63;catid=$key.html\" target=\"_blank\">$val</a>\n";
}
echo "<br/><br/><br/><br/>";
echo "<a href=&#63;>第一页</a>\n";
$str='';
for($i=1;$i<=$pnum-1;$i++)
{
  echo "<a href=\"&#63;page=$i\" target=\"_blank\"";
  if($i==$page){echo "style='color:red;'";};
  echo ">$i</a>\n\n";
}
echo "<a href=&#63;page=$pnum>最后一页</a>\n";
&#63;>

Copy after login

Readers who are interested in more PHP-related content can check out the special topics of this site: "Comprehensive collection of PHP array (Array) operation skills", "Summary of PHP regular expression usage" , "Summary of PHP ajax skills and applications", "Summary of PHP operations and operator usage", "Summary of PHP network programming skills", " Introduction to PHP basic syntax tutorial ", "Summary of PHP office document operation skills (including word, excel, access, ppt) ", "Summary of PHP date and time usage ", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "A summary of common PHP database operation skills

I hope this article will be helpful to everyone in PHP programming.

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!