1--TEST-- 2Test array_chunk() function : basic functionality - 'preserve_keys' as true/false 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$count = 1; 26// loop through each element of the array for input 27foreach ($input_arrays as $input_array){ 28 echo "\n-- Iteration $count --\n"; 29 var_dump( array_chunk($input_array, $size, true) ); 30 var_dump( array_chunk($input_array, $size, false) ); 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 [2]=> 51 int(3) 52 [3]=> 53 int(4) 54 } 55 [2]=> 56 array(1) { 57 [4]=> 58 int(5) 59 } 60} 61array(3) { 62 [0]=> 63 array(2) { 64 [0]=> 65 int(1) 66 [1]=> 67 int(2) 68 } 69 [1]=> 70 array(2) { 71 [0]=> 72 int(3) 73 [1]=> 74 int(4) 75 } 76 [2]=> 77 array(1) { 78 [0]=> 79 int(5) 80 } 81} 82 83-- Iteration 2 -- 84array(2) { 85 [0]=> 86 array(2) { 87 [0]=> 88 string(6) "value1" 89 [1]=> 90 string(6) "value2" 91 } 92 [1]=> 93 array(1) { 94 [2]=> 95 string(6) "value3" 96 } 97} 98array(2) { 99 [0]=> 100 array(2) { 101 [0]=> 102 string(6) "value1" 103 [1]=> 104 string(6) "value2" 105 } 106 [1]=> 107 array(1) { 108 [0]=> 109 string(6) "value3" 110 } 111} 112 113-- Iteration 3 -- 114array(2) { 115 [0]=> 116 array(2) { 117 ["key1"]=> 118 int(1) 119 ["key2"]=> 120 int(2) 121 } 122 [1]=> 123 array(1) { 124 ["key3"]=> 125 int(3) 126 } 127} 128array(2) { 129 [0]=> 130 array(2) { 131 [0]=> 132 int(1) 133 [1]=> 134 int(2) 135 } 136 [1]=> 137 array(1) { 138 [0]=> 139 int(3) 140 } 141} 142 143-- Iteration 4 -- 144array(2) { 145 [0]=> 146 array(2) { 147 [1]=> 148 string(3) "one" 149 [2]=> 150 string(3) "two" 151 } 152 [1]=> 153 array(1) { 154 [3]=> 155 string(5) "three" 156 } 157} 158array(2) { 159 [0]=> 160 array(2) { 161 [0]=> 162 string(3) "one" 163 [1]=> 164 string(3) "two" 165 } 166 [1]=> 167 array(1) { 168 [0]=> 169 string(5) "three" 170 } 171} 172 173-- Iteration 5 -- 174array(3) { 175 [0]=> 176 array(2) { 177 [1]=> 178 string(3) "one" 179 [2]=> 180 string(3) "two" 181 } 182 [1]=> 183 array(2) { 184 [3]=> 185 string(5) "three" 186 [4]=> 187 int(4) 188 } 189 [2]=> 190 array(1) { 191 ["five"]=> 192 int(5) 193 } 194} 195array(3) { 196 [0]=> 197 array(2) { 198 [0]=> 199 string(3) "one" 200 [1]=> 201 string(3) "two" 202 } 203 [1]=> 204 array(2) { 205 [0]=> 206 string(5) "three" 207 [1]=> 208 int(4) 209 } 210 [2]=> 211 array(1) { 212 [0]=> 213 int(5) 214 } 215} 216Done 217