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