fork download
  1. <?php
  2.  
  3. function paginate($currentPage, $maxPages, $pagesToShow)
  4. {
  5. $middle = ceil($pagesToShow/2);
  6. $pages = array();
  7. for($i = 1; $i<=$pagesToShow; $i++){
  8. if($currentPage<$middle){
  9. $pages[] = array('number'=> $i, 'active'=>($i==$currentPage)? true:false);
  10. }
  11.  
  12. elseif(($maxPages-$currentPage)<$middle){
  13. $pages[] = array('number'=> $maxPages-$pagesToShow+$i, 'active'=> ($pagesToShow-$i==$maxPages-$currentPage)? true:false);
  14. }
  15.  
  16. else{
  17. $pages[] = array('number' => $currentPage-($middle - $i), 'active'=> ($i==$middle)? true:false);
  18. }
  19. }
  20. return $pages;
  21. }
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Standard output is empty