有一个$A
是分页的数据:
$A = array(
0=>array(
0=>1,
1=>2
),
1=>array(
0=>3,
1=>5,
2=>2
),
2=>array(
0=>3,
1=>1,
2=>6,
3=>6
)
);
任何人都可以帮助我获得(output this "...." more)
最重要的预期输出吗?
....
告诉它还有更多元素需要显示下一页。或者它是上一页的剩余元素。
有要显示的09
元素$A
,所以
我设置
$show_per_page = 3;
输出(第一页):
1
2
Total:3
3
....//output this "...." more
输出(第二页):
....//output this "...." continue from first page
5
2
Total:10
3
.... //output this "...." more
输出(第三页):
.... //output this "...." continue from second page
1
6
6
Total:16
如果我设置
$show_per_page = 5;
输出(第一页):
1
2
Total:3
3
5
2
Total:10
// .... //not output this "...." more now
输出(第二页):
3
1
6
6
Total:16
如果我设置
$show_per_page = 9;
输出:
1
2
Total:3
3
5
2
Total:10
3
1
6
6
Total:16
目前我正在尝试使用该功能paging_from_multi_arr
,但我被困在如何实现获得加速结果的问题上:
// page to show (1-indexed)
// number of items to show per page
function paging_from_multi_arr($display_array, $page){
Global $show_per_page;
$start = $show_per_page * ($page-1);
$end = $show_per_page * $page;
$i = 0;
foreach($display_array as $main_order=>$section){
$total = 0;
foreach($section as $sub_order=>$value){
if($i >= $end){
break 2; // break out of both loops
}
$total += $value;
if($i >= $start){
echo $value.'<br>';
}
$i++;
}
if($i >= $start){
echo 'Total:'.$total.'<br>';
}
if($i >= $end){
break;
}
}
$total = count($display_array, COUNT_RECURSIVE);
// Total numbers of elements in $display_array array.
// See http://php.net/manual/en/function.count.php
if ($end < $total){
echo "...";
}
}
$show_per_page = 5;
paging_from_multi_arr($A,$_GET["page"]);
您对这里的功能有任何想法吗?或者可以给出更好的算法?
谢谢