PHP uses the array function for paging, Phparray function Paging _php tutorial

Source: Internet
Author: User

PHP uses the array function to implement paging, Phparray function paging


The code is simple, so there's no more nonsense.

The

copy Code code is as follows:
$array =array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20");//Specify 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);// 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);//Determine the next page, If the current page is the last page, click on the next page to display the last page
$current = ($current > ($total)? ( $total): $current);//If the 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 start reading
for ($i = $start , $i < ($start + $pagesize), $i + +) {
Array_push ($_return, $array [$i]);//Put the displayed information into the array $_return
}
$pagearray [ "Source"]=$_return;
$pagearray ["page"]= "first \" >prev next end;//the page style can be adjusted as needed
return $pagearray;
}

The above is the use of the array function to achieve the core of paging code, I hope you can like.

http://www.bkjia.com/PHPjc/958256.html www.bkjia.com true http://www.bkjia.com/PHPjc/958256.html techarticle PHP uses the array function to implement paging, Phparray function paging code is very simple, there is no more nonsense. Copy the code as follows: $array =array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "1 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.