PHP implements detailed explanation of the array paging processing instance and the logarithm instance
This article describes how PHP implements array paging. We will share this with you for your reference. The details are as follows:
Array data paging is recently used. The Code is as follows:
<? Phpclass PaginationArray {public $ pageArray = array (); // array public $ pageSize = 10; // number of records displayed on each page public $ current = 1; // current page private $ total = 0; // total number of pages private $ prev = 0; // Previous Page private $ next = 0; // next page public $ argumetsOther = ''; // set the Parameter function _ construct ($ array = array (), $ pageSize = 10, $ current = 1) {$ this-> pageArray = $ array; $ this-> pageSize = $ pageSize; $ this-> current = $ current;}/* initialize through array ** array as the associated array, parameter index as pageArray, page Size, current **/function setArguments ($ arr) {if (is_array ($ arr) {$ this-> pageArray = $ arr ['pagearray']; $ this-> pageSize = $ arr ['pagesize']; $ this-> current = $ arr ['stream'];} else {return ;}} // return link function page () {$ _ return = array ();/* calculator */$ this-> total = ceil (Count ($ this-> pageArray) /$ this-> pageSize); $ this-> prev = ($ this-> current-1) <= 0? "1" :( $ this-> current-1); $ this-> next = ($ this-> current + 1) >=$ this-> total? $ This-> total: $ this-> current + 1); $ current = ($ this-> current> ($ this-> total )? ($ This-> total): $ this-> current); $ start = ($ this-> current-1) * $ this-> pageSize; $ arrleng = count ($ this-> pageArray); for ($ I = $ start; $ I <($ start + $ this-> pageSize); $ I ++) {if ($ I >=$ arrleng) break; array_push ($ _ return, $ this-> pageArray [$ I]);} $ pagearray ["source"] =$ _ return; $ pagearray ["links"] = $ this-> linkStyle (2); return $ pagearray ;} // link Style private function linkStyle ($ number = 1) {$ linkStyle = ''; switch ($ number ){ Case 1: $ linkStyle = "<a href = \"? Page = 1 \ "> first </a> <a href = \"? Page = {$ this-> prev} \ "> prev </a> <a href = \"? Page = {$ this-> next }\ "> next </a> <a href = \"? Page = {$ this-> total} \ "> end </a>"; break; case 2: $ linkStyle = "<a href = \"? Page = 1 & {$ this-> argumetsOther} \ "> homepage </a> <a href = \"? Page = {$ this-> prev} & {$ this-> argumetsOther} \ "> previous page </a> <a href = \"? Page = {$ this-> next} & {$ this-> argumetsOther} \ "> next page </a> <a href = \"? Page = {$ this-> total} & {$ this-> argumetsOther} \ "> last page </a>"; break;} return $ linkStyle ;}} // The called instance/* 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", "19", "20 "); $ page = isset ($ _ GET ['page'])? $ _ GET ['page']: 1; $ arrayPage = new PaginationArray ($ array, "5", $ page); $ r = $ arrayPage-> page (); foreach ($ r ["source"] as $ s) {echo $ s. '<br/>';} echo $ r ["links"]; */?>