1: <?php
2:
3: namespace ngatngay;
4:
5: class arr
6: {
7: public static function getFromPage(array $data, int $page, int $perPage = 10): array
8: {
9: $result = [];
10: $total = count($data);
11: $start = ($page - 1) * $perPage;
12: $end = $start + $perPage;
13:
14: if ($start < 0) {
15: $start = 0;
16: }
17:
18: if ($end > $total) {
19: $end = $total;
20: }
21:
22: for ($start; $start < $end; $start++) {
23: $result[] = $data[$start];
24: }
25:
26: return $result;
27: }
28:
29: public static function toFile(string $filename, array $arr) {
30: return file_put_contents(
31: $filename,
32: '<?php return ' . var_export($arr, true) . ';'
33: );
34: }
35: }
36: