1--TEST--
2Test array_chunk() function : usage variations - unexpected values for 'preserve_keys'
3--FILE--
4<?php
5/* Prototype  : array array_chunk(array $array, int $size [, bool $preserve_keys])
6 * Description: Split array into chunks
7 * Source code: ext/standard/array.c
8*/
9
10/*
11* Testing array_chunk() function with unexpected values for 'preserve_keys'
12*/
13
14echo "*** Testing array_chunk() : usage variations ***\n";
15
16// input array
17$input = array(1, 2);
18$size = 10;
19
20//get an unset variable
21$unset_var = 10;
22unset ($unset_var);
23
24//array of values to iterate over
25$values = array(
26
27        // int data
28/*1*/   0,
29        1,
30        12345,
31        -2345,
32
33        // float data
34/*5*/   10.5,
35        -10.5,
36        10.5e10,
37        10.6E-10,
38        .5,
39
40        // null data
41/*10*/  NULL,
42        null,
43
44        // empty data
45/*12*/  "",
46        '',
47
48        // string data
49/*14*/  "string",
50        'string',
51
52        // object data
53/*16*/  new stdclass(),
54
55        // undefined data
56/*17*/  @$undefined_var,
57
58        // unset data
59/*18*/  @$unset_var
60
61);
62
63$count = 1;
64
65// loop through each element of the array for preserve_keys
66foreach($values as $value) {
67  echo "\n-- Iteration $count --\n";
68  var_dump( array_chunk($input, $size, $value) );
69  $count++;
70}
71
72echo "Done";
73?>
74--EXPECTF--
75*** Testing array_chunk() : usage variations ***
76
77-- Iteration 1 --
78array(1) {
79  [0]=>
80  array(2) {
81    [0]=>
82    int(1)
83    [1]=>
84    int(2)
85  }
86}
87
88-- Iteration 2 --
89array(1) {
90  [0]=>
91  array(2) {
92    [0]=>
93    int(1)
94    [1]=>
95    int(2)
96  }
97}
98
99-- Iteration 3 --
100array(1) {
101  [0]=>
102  array(2) {
103    [0]=>
104    int(1)
105    [1]=>
106    int(2)
107  }
108}
109
110-- Iteration 4 --
111array(1) {
112  [0]=>
113  array(2) {
114    [0]=>
115    int(1)
116    [1]=>
117    int(2)
118  }
119}
120
121-- Iteration 5 --
122array(1) {
123  [0]=>
124  array(2) {
125    [0]=>
126    int(1)
127    [1]=>
128    int(2)
129  }
130}
131
132-- Iteration 6 --
133array(1) {
134  [0]=>
135  array(2) {
136    [0]=>
137    int(1)
138    [1]=>
139    int(2)
140  }
141}
142
143-- Iteration 7 --
144array(1) {
145  [0]=>
146  array(2) {
147    [0]=>
148    int(1)
149    [1]=>
150    int(2)
151  }
152}
153
154-- Iteration 8 --
155array(1) {
156  [0]=>
157  array(2) {
158    [0]=>
159    int(1)
160    [1]=>
161    int(2)
162  }
163}
164
165-- Iteration 9 --
166array(1) {
167  [0]=>
168  array(2) {
169    [0]=>
170    int(1)
171    [1]=>
172    int(2)
173  }
174}
175
176-- Iteration 10 --
177array(1) {
178  [0]=>
179  array(2) {
180    [0]=>
181    int(1)
182    [1]=>
183    int(2)
184  }
185}
186
187-- Iteration 11 --
188array(1) {
189  [0]=>
190  array(2) {
191    [0]=>
192    int(1)
193    [1]=>
194    int(2)
195  }
196}
197
198-- Iteration 12 --
199array(1) {
200  [0]=>
201  array(2) {
202    [0]=>
203    int(1)
204    [1]=>
205    int(2)
206  }
207}
208
209-- Iteration 13 --
210array(1) {
211  [0]=>
212  array(2) {
213    [0]=>
214    int(1)
215    [1]=>
216    int(2)
217  }
218}
219
220-- Iteration 14 --
221array(1) {
222  [0]=>
223  array(2) {
224    [0]=>
225    int(1)
226    [1]=>
227    int(2)
228  }
229}
230
231-- Iteration 15 --
232array(1) {
233  [0]=>
234  array(2) {
235    [0]=>
236    int(1)
237    [1]=>
238    int(2)
239  }
240}
241
242-- Iteration 16 --
243
244Warning: array_chunk() expects parameter 3 to be bool, object given in %s on line %d
245NULL
246
247-- Iteration 17 --
248array(1) {
249  [0]=>
250  array(2) {
251    [0]=>
252    int(1)
253    [1]=>
254    int(2)
255  }
256}
257
258-- Iteration 18 --
259array(1) {
260  [0]=>
261  array(2) {
262    [0]=>
263    int(1)
264    [1]=>
265    int(2)
266  }
267}
268Done
269