<?php
/**
*---------------------------------------
* Originally written by Kjetil Hårtveit.
* www.kjetil-hartveit.com
*---------------------------------------
*
* Version 1.1 - 16.10.10 13:23
*
* @param array $allItems All of the items which you want to generate a pagelist of
* @param int $page Current page
* @param int $itemsPerPage Number of items you want to show per page
* @param array $pageList Pagelist passed by reference. Each key-pair consists of key as urlformat and value as the page number.
* @param string $urlFormat Optional url format. The first and only argument is the page number (%d).
* @return array The current page items
*/
function pageLister($allItems, $page, $itemsPerPage, &$pageList=array(), $urlFormat='%d')
{
$page = $page ? (int) $page : 1;
$numPages = ceil(count($allItems)/$itemsPerPage);
$pageList = array();
for ($i=1; $i<=$numPages; $i++)
{
$pageList[sprintf($urlFormat, $i)] = $i;
}
$currentPageItems = array_slice($allItems, ($page-1)*$itemsPerPage, $itemsPerPage);
return $currentPageItems;
}
?>