3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $total_pages = 100; $current_page = 50; $boundaries = 2; $around = 2; $arr1 = range(1, $boundaries); $arr2 = range($total_pages - max(($boundaries - 1), 0), $total_pages); $arr3 = range(min($current_page - $around, 1), $current_page); $arr4 = range($current_page, $current_page + $around); $result = array_unique(array_merge($arr1, $arr2, $arr3, $arr4)); sort($result); var_dump($arr1 ); ?>
based on o08eA
Output for 4.3.0 - 7.2.0
array(2) { [0]=> int(1) [1]=> int(2) }