Last active
April 30, 2020 06:22
-
-
Save haxianhe/0bfdb015815fa46e47a7e259e7c3985d to your computer and use it in GitHub Desktop.
分页
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//获取分页 | |
public static function getOffsetLimit($page = 1, $perpage = 50) { | |
if (empty($perpage)) { | |
$perpage = 50; | |
} | |
$page = max(1, $page); | |
$page = min(1000000, $page); | |
$perpage = max($perpage, 1); | |
$perpage = min(10000, $perpage); | |
$offset = $perpage * ($page - 1); | |
$limit = $perpage; | |
return [$offset, $limit]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment