1--TEST--
2Test array_chunk() function : basic functionality - default 'preserve_keys'
3--FILE--
4<?php
5echo "*** Testing array_chunk() : basic functionality ***\n";
6$size = 2;
7
8$input_arrays = array (
9  // array with default keys - numeric values
10  array(1, 2, 3, 4, 5),
11
12  // array with default keys - string values
13  array('value1', "value2", "value3"),
14
15  // associative arrays - key as string
16  array('key1' => 1, "key2" => 2, "key3" => 3),
17
18  // associative arrays - key as numeric
19  array(1 => 'one', 2 => "two", 3 => "three"),
20
21  // array containing elements with/without keys
22  array(1 => 'one','two', 3 => 'three', 4, "five" => 5)
23
24);
25
26$count = 1;
27// loop through each element of the array for input
28foreach ($input_arrays as $input_array){
29  echo "\n-- Iteration $count --\n";
30  var_dump( array_chunk($input_array, $size) );
31  $count++;
32}
33
34echo "Done"
35?>
36--EXPECT--
37*** Testing array_chunk() : basic functionality ***
38
39-- Iteration 1 --
40array(3) {
41  [0]=>
42  array(2) {
43    [0]=>
44    int(1)
45    [1]=>
46    int(2)
47  }
48  [1]=>
49  array(2) {
50    [0]=>
51    int(3)
52    [1]=>
53    int(4)
54  }
55  [2]=>
56  array(1) {
57    [0]=>
58    int(5)
59  }
60}
61
62-- Iteration 2 --
63array(2) {
64  [0]=>
65  array(2) {
66    [0]=>
67    string(6) "value1"
68    [1]=>
69    string(6) "value2"
70  }
71  [1]=>
72  array(1) {
73    [0]=>
74    string(6) "value3"
75  }
76}
77
78-- Iteration 3 --
79array(2) {
80  [0]=>
81  array(2) {
82    [0]=>
83    int(1)
84    [1]=>
85    int(2)
86  }
87  [1]=>
88  array(1) {
89    [0]=>
90    int(3)
91  }
92}
93
94-- Iteration 4 --
95array(2) {
96  [0]=>
97  array(2) {
98    [0]=>
99    string(3) "one"
100    [1]=>
101    string(3) "two"
102  }
103  [1]=>
104  array(1) {
105    [0]=>
106    string(5) "three"
107  }
108}
109
110-- Iteration 5 --
111array(3) {
112  [0]=>
113  array(2) {
114    [0]=>
115    string(3) "one"
116    [1]=>
117    string(3) "two"
118  }
119  [1]=>
120  array(2) {
121    [0]=>
122    string(5) "three"
123    [1]=>
124    int(4)
125  }
126  [2]=>
127  array(1) {
128    [0]=>
129    int(5)
130  }
131}
132Done
133