Home  >  Article  >  Backend Development  >  How to implement array paging in php

How to implement array paging in php

藏色散人
藏色散人Original
2021-03-08 11:02:593636browse

php method to implement array paging: first create a PHP sample file; then set the page utf encoding; finally pass "array_slice($array,($page-1)*$size,$size);" etc. Method to implement array paging.

How to implement array paging in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

How to simply implement array paging in php:

Learn something first and read more manuals
Use the functions that come with php to solve some difficult problems

<?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[&#39;page&#39;]?(int)$_GET[&#39;page&#39;]:&#39;0&#39;;
$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=&#39;&#39;;
for($i=1;$i<=$pnum-1;$i++)
{
  echo "<a href=\"?page=$i\" target=\"_blank\"";
  if($i==$page){echo "style=&#39;color:red;&#39;";};
  echo ">$i</a>\n\n";
}
echo "<a href=?page=$pnum>最后一页</a>\n";
?>

[Recommended: "PHP Video Tutorial"]

The above is the detailed content of How to implement array paging in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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