Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. function generatePagination(int $totalPages, int $displayPages, int $currentPage){
  4. if($displayPages%2===0){
  5. throw new Exception('Pass only odd no in display pages!');
  6. }
  7. $previousPages = [];
  8. $nextPages = [];
  9. $prev= $currentPage - (($displayPages+1)/2);
  10. for($i= $prev+1; $i<$currentPage;$i++){
  11. if($i<1){
  12. continue;
  13. }
  14. $previousPages[] = $i;
  15. }
  16. print_r($previousPages);
  17. $next = $displayPages - count($previousPages);
  18. print_r($next);
  19. print_r($currentPage);
  20. $next = $currentPage + $next;
  21. print_r($next);
  22. for($i= $currentPage+1; $i< $next; $i++){
  23. $nextPages[] = $i;
  24. }
  25. print_r($nextPages);
  26. return array_merge($previousPages, [$currentPage], $nextPages);
  27. }
  28.  
  29. $pages = generatePagination(50, 11, 1);
  30.  
  31. print_r($pages);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement