1--TEST-- 2Test array_chunk() function : usage variations - array with diff. sub 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 - input array containing different sub arrays 13*/ 14 15echo "*** Testing array_chunk() : usage variations ***\n"; 16 17$size = 2; 18 19// input array 20$input_array = array ( 21 "array1" => array(), 22 "array2" => array(1, 2, 3), 23 "array3" => array(1) 24); 25 26echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt --\n"; 27var_dump( array_chunk($input_array, $size) ); 28 29echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true --\n"; 30var_dump( array_chunk($input_array, $size, true) ); 31 32echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false --\n"; 33var_dump( array_chunk($input_array, $size, false) ); 34 35echo "Done"; 36?> 37--EXPECT-- 38*** Testing array_chunk() : usage variations *** 39 40-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt -- 41array(2) { 42 [0]=> 43 array(2) { 44 [0]=> 45 array(0) { 46 } 47 [1]=> 48 array(3) { 49 [0]=> 50 int(1) 51 [1]=> 52 int(2) 53 [2]=> 54 int(3) 55 } 56 } 57 [1]=> 58 array(1) { 59 [0]=> 60 array(1) { 61 [0]=> 62 int(1) 63 } 64 } 65} 66 67-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true -- 68array(2) { 69 [0]=> 70 array(2) { 71 ["array1"]=> 72 array(0) { 73 } 74 ["array2"]=> 75 array(3) { 76 [0]=> 77 int(1) 78 [1]=> 79 int(2) 80 [2]=> 81 int(3) 82 } 83 } 84 [1]=> 85 array(1) { 86 ["array3"]=> 87 array(1) { 88 [0]=> 89 int(1) 90 } 91 } 92} 93 94-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false -- 95array(2) { 96 [0]=> 97 array(2) { 98 [0]=> 99 array(0) { 100 } 101 [1]=> 102 array(3) { 103 [0]=> 104 int(1) 105 [1]=> 106 int(2) 107 [2]=> 108 int(3) 109 } 110 } 111 [1]=> 112 array(1) { 113 [0]=> 114 array(1) { 115 [0]=> 116 int(1) 117 } 118 } 119} 120Done 121