<?php
use Laminas\Paginator\Adapter\ArrayAdapter;
use Laminas\Paginator\Paginator;
$data = [
['id' => 1, 'name' => 'one'],
['id' => 2, 'name' => 'two'],
['id' => 3, 'name' => 'three'],
['id' => 4, 'name' => 'four'],
['id' => 5, 'name' => 'five'],
['id' => 6, 'name' => 'six'],
['id' => 7, 'name' => 'seven'],
];
$adapter = new ArrayAdapter($data);
$paginator = new Paginator($adapter);
$paginator->setItemCountPerPage(4);
echo sprintf(
'page %d of %d'. PHP_EOL,
$paginator->getCurrentPageNumber(),
count($paginator)
);
foreach($paginator as $item) {
echo $item['id'] . ' = ' .
$item['name'] . PHP_EOL;
}
// go to page 2
$paginator->setCurrentPageNumber(2);
echo sprintf(
'page %d of %d'. PHP_EOL,
$paginator->getCurrentPageNumber(),
count($paginator)
);
foreach($paginator as $item) {
echo $item['id'] . ' = ' .
$item['name'] . PHP_EOL;
}