新聞中心
/**
創(chuàng)新互聯(lián)公司專注于貴定網(wǎng)站建設服務及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗。 熱誠為您提供貴定營銷型網(wǎng)站建設,貴定網(wǎng)站制作、貴定網(wǎng)頁設計、貴定網(wǎng)站官網(wǎng)定制、小程序開發(fā)服務,打造貴定網(wǎng)絡公司原創(chuàng)品牌,更為您提供貴定網(wǎng)站排名全網(wǎng)營銷落地服務。
* 分頁函數(shù) 核心函數(shù) array_slice
* 用此函數(shù)之前要先將數(shù)據(jù)庫里面的所有數(shù)據(jù)按一定的順序查詢出來存入數(shù)組中
* $count 每頁展示多少數(shù)據(jù)
* $page 當前第幾頁
* $array 分頁數(shù)組
* $order 0 - 不變 1 - 反序
*/
public function page_array($page, $array, $count = 10, $order = 0) {
$page = (empty($page)) ? 1 : $page; # 判斷是否為空如果為空展示第一頁
$start = ($page - 1) * $count; # 計算每次分頁的開始位置
if ($order == 1) {
$array = array_reverse($array);
}
$totals = count($array);
$countpage = ceil($totals / $count); # 計算總頁面數(shù)
$pagedata = array();
$pagedata = array_slice($array, $start, $count);
return $pagedata; # 返回查詢數(shù)據(jù)
}
當前名稱:php數(shù)組分頁array_slice
文章來源:http://fisionsoft.com.cn/article/joshho.html