PHPackages                             smhnaqvi/pagination - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. smhnaqvi/pagination

ActiveLibrary

smhnaqvi/pagination
===================

simple library for easily create pagination with json format for rest api responses

20PHP

Since Oct 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/smhnaqvi/php-pagination)[ Packagist](https://packagist.org/packages/smhnaqvi/pagination)[ RSS](/packages/smhnaqvi-pagination/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

php-pagination
==============

[](#php-pagination)

#### simple library to create easily pagination for rest apis json response

[](#simple-library-to-create-easily-pagination-for-rest-apis-json-response)

### install package using composer

[](#install-package-using-composer)

```
composer require smhnaqvi/json-response

```

#### OR

[](#or)

### clone from github repository

[](#clone-from-github-repository)

```
git clone git@github.com:smhnaqvi/php-json-response.git

```

### usage

[](#usage)

```
use Libraries\Pagination\Pagination;

// create Pagination instance
// argument 1 has number of total records and accept integer value
// argument 2 is current page number by default its 1 integer value
// argument 3 is number of how many showing result per page and by default its 10 integer value
$records = 52;
$currentPage = 6;
$showPerPage = 3;
$paging = new Pagination($records, $currentPage, $showPerPage);
```

### ::paginate

[](#paginate)

return pagination `object`

```
$paginate = $paging->paginate();
$total = $paginate->total;
$current_page = $paginate->current_page;
$all_pages = $paginate->all_pages;
$per_page = $paginate->per_page;
$has_pagination = $paginate->has_pagination;
```

### ::toJson

[](#tojson)

show pagination final result and using `exit()` to stop php process and `json_encode()` to encode data to json .

```
$paging->toJson();
```

### ::toArray

[](#toarray)

return `array` of pagination object

```
$pageArr = $paging->toArray();
$total = $pageArr["total"];
$current_page = $pageArr["current_page"];
$all_pages = $pageArr["all_pages"];
$per_page = $pageArr["per_page"];
$has_pagination = $pageArr["has_pagination"];
```

### ::getOffset

[](#getoffset)

return calculated offset for pagination

```
$offset = $paging->getOffset(); // return int value
```

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3da63afa96b48bc299e664faf86802e0a2620fea8a657c87bc03f501d7e9b491?d=identicon)[smhnaqvi](/maintainers/smhnaqvi)

---

Top Contributors

[![smhnaqvi](https://avatars.githubusercontent.com/u/22330581?v=4)](https://github.com/smhnaqvi "smhnaqvi (1 commits)")

### Embed Badge

![Health badge](/badges/smhnaqvi-pagination/health.svg)

```
[![Health](https://phpackages.com/badges/smhnaqvi-pagination/health.svg)](https://phpackages.com/packages/smhnaqvi-pagination)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
