Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function generatePagination(int $totalPages, int $displayPages, int $currentPage){
- if($displayPages%2===0){
- throw new Exception('Pass only odd no in display pages!');
- }
- $previousPages = [];
- $nextPages = [];
- $prev= $currentPage - (($displayPages+1)/2);
- for($i= $prev+1; $i<$currentPage;$i++){
- if($i<1){
- continue;
- }
- $previousPages[] = $i;
- }
- print_r($previousPages);
- $next = $displayPages - count($previousPages);
- print_r($next);
- print_r($currentPage);
- $next = $currentPage + $next;
- print_r($next);
- for($i= $currentPage+1; $i< $next; $i++){
- $nextPages[] = $i;
- }
- print_r($nextPages);
- return array_merge($previousPages, [$currentPage], $nextPages);
- }
- $pages = generatePagination(50, 11, 1);
- print_r($pages);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement