Home > Article > Backend Development > Number of page numbers for circular paging
$page = 1;
$total = 20;
$prevs = $page - 4;
if($prevs <= 0) {
$prevs = 1;
}
$next = $page + 4;
if($next > $total) {
$next = $total;
}
for($i = $prevs; $i <= $page - 1; $i++) {
echo $i."rn";
}
echo '['.$page.']'."rn";
for($i = $page + 1; $i <= $next; $i++) {
echo $i."rn";
}