Annotation of embedaddon/php/ext/standard/tests/array/array_chunk_variation5.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_chunk() function : usage variations - different 'size' values
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. -ve size value
14: * 2. size value is more than the no. of elements in the input array
15: * 3. size value is zero
16: * 4. Decimal size value
17: */
18:
19: echo "*** Testing array_chunk() : usage variations ***\n";
20:
21: // input array
22: $input_array = array(1, 2, 3);
23:
24: // different magnitude's
25: $sizes = array(-1, count($input_array) + 1, 0, 1.5);
26:
27: // loop through the array for size argument
28: foreach ($sizes as $size){
29: echo "\n-- Testing array_chunk() when size = $size --\n";
30: var_dump( array_chunk($input_array, $size) );
31: var_dump( array_chunk($input_array, $size, true) );
32: var_dump( array_chunk($input_array, $size, false) );
33: }
34: echo "Done";
35: ?>
36: --EXPECTF--
37: *** Testing array_chunk() : usage variations ***
38:
39: -- Testing array_chunk() when size = -1 --
40:
41: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
42: NULL
43:
44: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
45: NULL
46:
47: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
48: NULL
49:
50: -- Testing array_chunk() when size = 4 --
51: array(1) {
52: [0]=>
53: array(3) {
54: [0]=>
55: int(1)
56: [1]=>
57: int(2)
58: [2]=>
59: int(3)
60: }
61: }
62: array(1) {
63: [0]=>
64: array(3) {
65: [0]=>
66: int(1)
67: [1]=>
68: int(2)
69: [2]=>
70: int(3)
71: }
72: }
73: array(1) {
74: [0]=>
75: array(3) {
76: [0]=>
77: int(1)
78: [1]=>
79: int(2)
80: [2]=>
81: int(3)
82: }
83: }
84:
85: -- Testing array_chunk() when size = 0 --
86:
87: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
88: NULL
89:
90: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
91: NULL
92:
93: Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
94: NULL
95:
96: -- Testing array_chunk() when size = 1.5 --
97: array(3) {
98: [0]=>
99: array(1) {
100: [0]=>
101: int(1)
102: }
103: [1]=>
104: array(1) {
105: [0]=>
106: int(2)
107: }
108: [2]=>
109: array(1) {
110: [0]=>
111: int(3)
112: }
113: }
114: array(3) {
115: [0]=>
116: array(1) {
117: [0]=>
118: int(1)
119: }
120: [1]=>
121: array(1) {
122: [1]=>
123: int(2)
124: }
125: [2]=>
126: array(1) {
127: [2]=>
128: int(3)
129: }
130: }
131: array(3) {
132: [0]=>
133: array(1) {
134: [0]=>
135: int(1)
136: }
137: [1]=>
138: array(1) {
139: [0]=>
140: int(2)
141: }
142: [2]=>
143: array(1) {
144: [0]=>
145: int(3)
146: }
147: }
148: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>