[ create a new paste ] login | about

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

PHP, pasted on Sep 27:
<?php

$total = 1024;
$per_page = 10;
$current_page = 2;
$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] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)


Create a new paste based on this one


Comments: