3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 . " "; } ?>
based on 0WI5G
Output for 4.3.0 - 7.2.6
1 2 ... 10