开发者

Writing a number in an array that has the same number of counts like the number

I am working on a paging function. This is what I have:

$total_pages = 3; // 3 is only an example

foreach ($total_pages as $single_page):
echo 'Page'.$single_site->number.'|';
endforeach;

How can I write the number of pages in array that I can use in my foreach function?

The number of pages is dynamical. I want to be able, to show a value for each 开发者_运维技巧page like: Page1, Page2 and so on. Dependening on the number of total pages.


You can use range():

foreach (range(0, $total_pages - 1) as $single_page)

but even easier is to just use a normal for loop:

for($i = 0; $i < $total_pages; $i++)


Zend Paginator is a great way to paginate data, and makes it relatively easy to implement a scrolling pagination control (showing only a subset of pages numbers relative to the current page number). If your application has a lot of pages of results, then showing a scrolling pagination control will provide a better user experience than showing hundreds of "Page X" links in succession.

A sliding control might look like: [Prev] 1 ... 4 5 6 7 8 ... 200 [Next]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜