The code is very simple, it is not a lot of nonsense.
Copy Code code as follows:
$array =array ("1", "2", "3", "4", "5", "6", "" 7 "," 8 "," 9 "," 10 "," 11 "," 12 "," 13 "," 14 "," 15 "," 16 "," 17 "," 18 "," 19 "," 20 "); Set the array to be paged
$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);//Find total Pages
$prev = (($current-1) <=0? "1":($current-1))//Determine the previous page, if the current page is the first page, click to display the first page
$next = (($current + 1) >= $total? $total: $current + 1);/OK next page, if the current page is the last page, click Next page to display the last page
$current = ($current > ($total)? ( $total): $current);//current page is greater than the total number of pages, the current page is the last page
$start = ($current-1) * $pagesize///When pagination is displayed, how many messages should be read from
for ($i = $start; $i < ($start + $pagesize); $i + +) {
Array_push ($_return, $array [$i]);//Put the displayed information in an array $_return
}
$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> ";//pagination styles can be adjusted as needed
return $pagearray;
}
The above is the use of the array function to achieve pagination of the core code, I hope you can enjoy.