vvval / spiral-array-paginable
Wrapper to allow paginate arrays.
Installs: 2 118
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
- spiral/common: ^1.0
- spiral/pagination: ^1.0
Requires (Dev)
- phpunit/phpunit: ~6.0
- spiral/framework: ^1.0
This package is auto-updated.
Last update: 2024-11-28 02:08:56 UTC
README
Small helper, that grants ability to paginate arrays in RecordSource way. Created for Spiral Framework
Usage
//Example input data $data = [ 'one' => 10, 'two' => 20, 'three' => 30, 'four' => 40, 'five' => 50, 'six' => 60, 'seven' => 70, 'eight' => 80, 'nine' => 90, 'ten' => 100, ]; $paginable = new PaginableArray($data); $paginable->paginate(5); //Implements `\Iterator` so you can just use it in foreach cycle foreach ($paginable as $value) { echo $value; // 10, 20, 30, 40, 50 for first page } //Also preserves keys. To access them during foreach cycle use `iterate()` method foreach ($paginable->iterate() as $key => $value) { echo $key; // one, two, three, four, five for first page }