php数组分页函数

/**
 * 数组分页函数
 * $data 分页数组
 * $p 当前页码
 * $size 每页显示数量
 */

function page_array($data,$p,$size) {
    $start=($p-1)*$size;
    $list =array_slice($data,$start,$size,TRUE); 
    $total = count($data); //总数
    $obj = new Pager($total, $size, 5); //分页类
    $page = $obj->show(); //页码输出
    return array(
        "data"=>$list, //分页好的数据
        "page"=>$page, //页码HTML
    );
}

  就这么简单,其实数组分页就是用到php自带的一个函数 array_slice(), 关于它的具体用法可以参考php官网

  希望对你有用! 技术支持:点滴网

你可能感兴趣的:(php数组分页函数)