Skip to content

Instantly share code, notes, and snippets.

View prajwal89's full-sized avatar

Prajwal Hallale prajwal89

View GitHub Profile
@prajwal89
prajwal89 / google_like_pagination.php
Last active November 2, 2022 10:54
Google like pagination logic that keeps current page in the middle and keeps number of pages in pagination same if possible.
<?php
function get_pagination_range(int $current_page, int $total_pages, int $each_side): array
{
if ($current_page > $total_pages) {
return []; //current page should be smaller than total pages
}
$start = $current_page - $each_side;