PHPackages                             valksor/php-functions-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. valksor/php-functions-pagination

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

valksor/php-functions-pagination
================================

A PHP library providing pagination functionality to generate page numbers for UI pagination controls, with smart handling of large page sets

00PHPCI passing

Since Dec 28Pushed 3mo agoCompare

[ Source](https://github.com/valksor/php-functions-pagination)[ Packagist](https://packagist.org/packages/valksor/php-functions-pagination)[ RSS](/packages/valksor-php-functions-pagination/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Valksor Functions: Pagination
=============================

[](#valksor-functions-pagination)

[![valksor](https://camo.githubusercontent.com/2af5a6a7e5f7da47cd0a924c8b00038f208f45f9b0d5be8d7a497a9808168187/68747470733a2f2f62616467656e2e6e65742f7374617469632f6f72672f76616c6b736f722f677265656e)](https://github.com/valksor)[![BSD-3-Clause](https://camo.githubusercontent.com/72547f8afb6b5ace804caebbf95c3bcbfc027ce9214777bc452f308f3165db01/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4253442d2d332d2d436c617573652d677265656e3f7374796c653d666c6174)](https://github.com/valksor/php-functions-pagination/blob/master/LICENSE)[![Coverage Status](https://camo.githubusercontent.com/7b7793f36da83f8256cfbd03c83f79e6dadbca00a5e6d4ee00122a548329eba9/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f76616c6b736f722f7068702d66756e6374696f6e732d706167696e6174696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/valksor/php-functions-pagination?branch=master)[![php](https://camo.githubusercontent.com/77da2f7bbc049873edb2d1045a756d7a32e3ba50440a8e0e76a9109f62f0771b/68747470733a2f2f62616467656e2e6e65742f7374617469632f7068702f2533453d382e342f707572706c65)](https://www.php.net/releases/8.4/en.php)

A PHP library providing pagination functionality to generate page numbers for UI pagination controls, with smart handling of large page sets.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require valksor/php-functions-pagination
```

Requirements
------------

[](#requirements)

PHP 8.4 or higher

Usage
-----

[](#usage)

The Pagination class provides a mechanism to generate pagination data for displaying page numbers in a UI, with intelligent handling of omitted pages.

### Basic Usage

[](#basic-usage)

```
use Valksor\Functions\Pagination\Pagination;

// Create a new Pagination instance
$pagination = new Pagination();

// Generate pagination data
$pages = $pagination->paginate(
    7,       // Number of visible pages
    20,      // Total number of pages
    5,       // Current page
    -1       // Indicator for omitted pages (optional, defaults to -1)
);

// $pages will contain an array like: [1, 2, 3, 4, 5, 6, 7, -1, 20]
// where -1 represents omitted pages
```

### Different Pagination Scenarios

[](#different-pagination-scenarios)

The pagination algorithm intelligently handles different scenarios:

#### All Pages Visible

[](#all-pages-visible)

When the total number of pages is less than or equal to the number of visible pages:

```
$pages = $pagination->paginate(10, 8, 4); // [1, 2, 3, 4, 5, 6, 7, 8]
```

#### Single Omitted Section

[](#single-omitted-section)

When the current page is near the beginning or end:

```
// Current page near beginning
$pages = $pagination->paginate(7, 20, 3); // [1, 2, 3, 4, 5, -1, 20]

// Current page near end
$pages = $pagination->paginate(7, 20, 18); // [1, -1, 16, 17, 18, 19, 20]
```

#### Two Omitted Sections

[](#two-omitted-sections)

When the current page is in the middle of a large set:

```
$pages = $pagination->paginate(7, 20, 10); // [1, -1, 8, 9, 10, 11, 12, -1, 20]
```

Features
--------

[](#features)

- **Smart page generation**: Intelligently generates page numbers for UI pagination controls
- **Omitted page handling**: Uses indicators to show where pages are omitted in large sets
- **Configurable visible pages**: Control how many page numbers are shown
- **Flexible indicators**: Customize the indicator value for omitted pages
- **Input validation**: Comprehensive validation of all input parameters
- **Multiple scenarios**: Handles current page at beginning, middle, or end of page set

For a complete list of all functions available in this package, see [Features](docs/features.md).

Validation
----------

[](#validation)

The class performs several validations:

- The number of visible pages must be at least 5
- The total number of pages must be at least 1
- The current page must be between 1 and the total number of pages
- The indicator value must not be a valid page number (between 1 and total)

Contributing
------------

[](#contributing)

Contributions are welcome!

- Code style requirements (PSR-12)
- Testing requirements for PRs
- One feature per pull request
- Development setup instructions

To contribute to Pagination functions:

1. Fork repository
2. Create a feature branch (`git checkout -b feature/new-pagination-function`)
3. Implement your function following existing patterns
4. Add comprehensive tests including edge cases
5. Ensure all tests pass and code style is correct
6. Submit a pull request

Security
--------

[](#security)

If you discover any security-related issues, please email us at  instead of using the issue tracker.

Support
-------

[](#support)

- **Documentation**: [Full documentation](https://github.com/valksor/php-valksor)
- **Issues**: [GitHub Issues](https://github.com/valksor/php-valksor/issues) for bug reports and feature requests
- **Discussions**: [GitHub Discussions](https://github.com/orgs/valksor/discussions/categories/php-valksor) for questions and community support

Credits
-------

[](#credits)

- **[Original Author](https://github.com/valksor)** - Creator and maintainer
- **[All Contributors](https://github.com/valksor/php-valksor/graphs/contributors)** - Thank you to all who contributed
- **[Relevant PHP Documentation](https://www.php.net/manual/en/)** - Core PHP functionality inspiration
- **[Valksor Project](https://github.com/valksor)** - Part of the larger Valksor PHP ecosystem

License
-------

[](#license)

This package is licensed under the [BSD-3-Clause License](LICENSE).

About Valksor
-------------

[](#about-valksor)

This package is part of the [valksor/php-valksor](https://github.com/valksor/php-valksor) project - a comprehensive PHP library and Symfony bundle that provides a collection of utilities, components, and integrations for Symfony applications.

The main project includes:

- Various utility functions and components
- Doctrine ORM tools and extensions
- Symfony bundle for easy configuration
- And much more

If you find this Pagination component useful, you might want to check out the full Valksor project for additional tools and utilities that can enhance your Symfony application development.

To install the complete package:

```
composer require valksor/php-valksor
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance53

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

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/c4db85e32518c5a6caa2fd625032a2b016ef42d60cf8a101c165cc5c0048b221?d=identicon)[k0d3r1s](/maintainers/k0d3r1s)

---

Top Contributors

[![k0d3r1s](https://avatars.githubusercontent.com/u/38725938?v=4)](https://github.com/k0d3r1s "k0d3r1s (36 commits)")

### Embed Badge

![Health badge](/badges/valksor-php-functions-pagination/health.svg)

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

###  Alternatives

[jeroen/rewindable-generator

Provides a simple adapter to make generators rewindable

1655.4k2](/packages/jeroen-rewindable-generator)[breadlesscode/neos-nodetypes-folder

Folder nodetype for Neos CMS

1088.5k1](/packages/breadlesscode-neos-nodetypes-folder)

PHPackages © 2026

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