0 ? 1 : 0)); // $totalPage = 100; // $page = 50; if ($totalPage <= 0) { exit; } if ($page > $totalPage) { $page = $totalPage; } if ($page < 1) { $page = 1; } $showPageButtonNumArray = array(); if ($totalPage <= $centerButtonCount + 2) { $showPageButtonNumArray += range(1, $totalPage); } else { $halfButtonNum = intval($centerButtonCount / 2); if ($page <= $halfButtonNum) { $centerButtonNumArray = range(2, $centerButtonCount); } else if ($page + $halfButtonNum < $totalPage) { $centerButtonNumArray = range($page - $halfButtonNum, $page + $halfButtonNum); } else { $centerButtonNumArray = range($totalPage - $centerButtonCount, $totalPage); } if ($centerButtonNumArray[0] > 1) { array_push($showPageButtonNumArray, 1); } if ($centerButtonNumArray[0] > 2) { array_push($showPageButtonNumArray, ""); } $showPageButtonNumArray = array_merge($showPageButtonNumArray, $centerButtonNumArray); if ($centerButtonNumArray[count($centerButtonNumArray) - 1] < $totalPage - 1) { array_push($showPageButtonNumArray, ""); } if ($centerButtonNumArray[count($centerButtonNumArray) - 1] < $totalPage) { array_push($showPageButtonNumArray, $totalPage); } } echo "