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