|
| |
1 |
|
<?php |
|
| |
2 |
|
|
|
| |
3 |
|
|
|
| |
4 |
|
|
|
| |
5 |
|
|
|
| |
6 |
|
|
|
| |
7 |
|
|
|
| |
8 |
|
|
|
| |
9 |
|
|
|
| |
10 |
|
|
|
| |
11 |
|
|
|
| |
12 |
|
|
|
| |
13 |
|
|
|
| |
14 |
|
|
|
| |
15 |
|
|
|
| |
16 |
|
|
|
| |
17 |
|
|
|
| |
18 |
|
|
|
| |
19 |
|
|
|
| |
20 |
|
|
|
| |
21 |
|
|
|
| |
22 |
|
|
|
| |
23 |
|
|
|
| |
24 |
|
|
|
| |
25 |
|
|
|
| |
26 |
|
|
|
| |
27 |
|
|
|
| |
28 |
|
|
|
| |
29 |
|
|
|
| |
30 |
|
|
|
| |
31 |
|
|
|
| |
32 |
|
|
|
| |
33 |
|
|
|
| |
34 |
|
|
|
| |
35 |
|
if (!function_exists('array_chunk')) |
|
| |
36 |
|
{ |
|
| |
37 |
|
function array_chunk ($input, $size, $preserve_keys = false) |
|
| |
38 |
|
{ |
|
| |
39 |
|
if (!is_array($input)) { |
|
| |
40 |
|
trigger_error('array_chunk() expects parameter 1 to be array, ' . gettype($input) . ' given', E_USER_WARNING); |
|
| |
41 |
|
return null; |
|
| |
42 |
|
} |
|
| |
43 |
|
|
|
| |
44 |
|
if (!is_numeric($size)) { |
|
| |
45 |
|
trigger_error('array_chunk() expects parameter 2 to be long, ' . gettype($size) . ' given', E_USER_WARNING); |
|
| |
46 |
|
return null; |
|
| |
47 |
|
} |
|
| |
48 |
|
|
|
| |
49 |
|
$size = (int)$size; |
|
| |
50 |
|
if ($size <= 0) |
|
| |
51 |
|
{ |
|
| |
52 |
|
trigger_error('array_chunk() Size parameter expected to be greater than 0', E_USER_WARNING); |
|
| |
53 |
|
return null; |
|
| |
54 |
|
} |
|
| |
55 |
|
|
|
| |
56 |
|
$chunks = array(); |
|
| |
57 |
|
$i = 0; |
|
| |
58 |
|
|
|
| |
59 |
|
if ($preserve_keys !== false) |
|
| |
60 |
|
{ |
|
| |
61 |
|
foreach ($input as $key => $value) { |
|
| |
62 |
|
$chunks[(int)($i++ / $size)][$key] = $value; |
|
| |
63 |
|
} |
|
| |
64 |
|
} |
|
| |
65 |
|
else |
|
| |
66 |
|
{ |
|
| |
67 |
|
foreach ($input as $value) { |
|
| |
68 |
|
$chunks[(int)($i++ / $size)][] = $value; |
|
| |
69 |
|
} |
|
| |
70 |
|
} |
|
| |
71 |
|
|
|
| |
72 |
|
return $chunks; |
|
| |
73 |
|
} |
|
| |
74 |
|
} |
|
| |
75 |
|
|
|
| |
76 |
|
?> |