- 很多時(shí)候業(yè)務(wù)需要的數(shù)據(jù)需要對(duì)于查詢出來(lái)的數(shù)據(jù)進(jìn)行歸類,比如:以時(shí)間為維度,將sql查詢出來(lái)的數(shù)據(jù)根據(jù)月份歸類,比如下邊的這種數(shù)據(jù)結(jié)構(gòu),對(duì)于這種業(yè)務(wù)要求的數(shù)據(jù),或者類似這種的需要重新分組歸類處理的數(shù)據(jù)結(jié)構(gòu),甚至比這種更復(fù)雜的數(shù)據(jù),直接用sql實(shí)現(xiàn)分頁(yè)有時(shí)候就無(wú)法滿足需求了
Array
(
[2019-06-24] => Array
(
[0] => Array
(
[name] => 張三
[age] => 23
[registerTime] => 2019-06-24 08:12:36
)
[1] => Array
(
[name] => 李四
[age] => 89
[registerTime] => 2019-06-24 13:32:48
)
)
[2019-06-25] => Array
(
[0] => Array
(
[name] => 王五
[age] => 45
[registerTime] => 2019-06-25 15:21:12
)
[1] => Array
(
[name] => 趙四
[age] => 34
[registerTime] => 2019-06-24 20:09:02
)
)
)
$count = count($data);//計(jì)算總數(shù)據(jù)量
$skip = ($page - 1) * $pageSize;//計(jì)算分頁(yè)偏移量
$pagingData = array_slice($data,$skip,$pageSize,true);//實(shí)現(xiàn)數(shù)組分頁(yè)