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