<?php
$total_pages = 10;
$current_page = 1;
$boundaries = 1;
$around = 1;
$startPages = range(1, max($boundaries, 1));
$endPages = range($total_pages - max(($boundaries - 1), 0), $total_pages);
$aroundLeft = range(max($current_page - $around, 1), $current_page);
$aroundRight = range($current_page, min($current_page + $around, $total_pages));
$result = array_values(array_unique(array_merge($startPages, $aroundLeft, $aroundRight, $endPages)));
$final = array();
for($i = 0; $i<count($result) -1;$i++) {
array_push($final, $result[$i]);
if($result[$i+1] - $result[$i] > 1) {
array_push($final, "...");
}
}
array_push($final, $result[count($result) - 1]);
foreach($final as $item) {
echo $item . " ";
}
?>
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- 1 2 ... 10
preferences:
264.12 ms | 406 KiB | 354 Q