Skip to content

Instantly share code, notes, and snippets.

@fernandosavio
Created May 25, 2013 00:43
Show Gist options
  • Save fernandosavio/5647446 to your computer and use it in GitHub Desktop.
Save fernandosavio/5647446 to your computer and use it in GitHub Desktop.
Script que retorna um range do números das páginas baseado nos parâmetros recebidos.
<?php
function pagination ($index, $teto, $amplitude = 7, $piso = 1){
$padding = intval($amplitude/2);
$amplitude = min(array($amplitude,$teto));
$left = $padding;
$right = $amplitude - $left - 1;
if($index - $padding < $piso){
$left = $index - $piso;
$right = $amplitude - ($left + 1);
}
if($index + $padding > $teto){
$right = $teto - $index;
$left = $amplitude - ($right + 1);
}
return range($index - $left, $index + $right);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment