[ create a new paste ] login | about

Link: http://codepad.org/HAKkgrb2    [ raw code | output | fork ]

PHP, pasted on Sep 27:
<?php

$total = 1024;
$per_page = 10;
$current_page = 42;
$adjacent_links = 4;

function Pagination($data, $limit = null, $current = null, $adjacents = null)
{
	$result = array();

	if (isset($data, $limit) === true)
	{
		$result = range(1, ceil($data / $limit));

		if (isset($current, $adjacents) === true)
		{
			if (($adjacents = floor($adjacents / 2) * 2 + 1) >= 1)
			{
				$result = array_slice($result, max(0, min(count($result) - $adjacents, intval($current) - ceil($adjacents / 2))), $adjacents);
			}
		}
	}

	return $result;
}

print_r(Pagination($total, $per_page, $current_page, $adjacent_links));

?>


Output:
1
2
3
4
5
6
7
8
Array
(
    [0] => 40
    [1] => 41
    [2] => 42
    [3] => 43
    [4] => 44
)


Create a new paste based on this one


Comments: