Annotation of embedaddon/php/ext/standard/tests/array/array_combine_variation3.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test array_combine() function : usage variations - different arrays(Bug#43424)
3: --FILE--
4: <?php
5: /* Prototype : array array_combine(array $keys, array $values)
6: * Description: Creates an array by using the elements of the first parameter as keys
7: * and the elements of the second as the corresponding values
8: * Source code: ext/standard/array.c
9: */
10:
11: /*
12: * Passing different types of arrays to both $keys and $values arguments and testing whether
13: * array_combine() behaves in an expected way with the arguments passed to the function
14: */
15:
16: echo "*** Testing array_combine() : Passing different types of arrays to both \$keys and \$values argument ***\n";
17: /* Different heredoc strings passed as argument to arrays */
18: // heredoc with blank line
19: $blank_line = <<<EOT
20:
21:
22: EOT;
23:
24: // heredoc with multiline string
25: $multiline_string = <<<EOT
26: hello world
27: The quick brown fox jumped over;
28: the lazy dog
29: This is a double quoted string
30: EOT;
31:
32: // heredoc with diferent whitespaces
33: $diff_whitespaces = <<<EOT
34: hello\r world\t
35: 1111\t\t != 2222\v\v
36: heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
37: EOT;
38:
39: // heredoc with quoted strings and numeric values
40: $numeric_string = <<<EOT
41: 11 < 12. 123 >22
42: 'single quoted string'
43: "double quoted string"
44: 2222 != 1111.\t 0000 = 0000\n
45: EOT;
46:
47: // arrays passed to $keys argument
48: $arrays = array (
49: /*1*/ array(1, 2), // with default keys and numeric values
50: array(1.1, 2.2), // with default keys & float values
51: array(false,true), // with default keys and boolean values
52: array(), // empty array
53: /*5*/ array(NULL), // with NULL
54: array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings
55: array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings
56: array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs
57:
58: // associative arrays
59: /*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values
60: array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values
61: array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values
62: array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value
63: array("one" => 1, 2 => "two", 4 => "four"), //mixed
64:
65: // associative array, containing null/empty/boolean values as key/value
66: /*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
67: array(true => "true", false => "false", "false" => false, "true" => true),
68: array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
69: array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
70: array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
71:
72: // array with repetative keys
73: /*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
74: );
75:
76: // loop through each sub-array within $arrays to check the behavior of array_combine()
77: // same arrays are passed to both $keys and $values
78: $iterator = 1;
79: foreach($arrays as $array) {
80: echo "-- Iteration $iterator --\n";
81: var_dump( array_combine($array, $array) );
82: $iterator++;
83: }
84:
85: echo "Done";
86: ?>
87: --EXPECTF--
88: *** Testing array_combine() : Passing different types of arrays to both $keys and $values argument ***
89: -- Iteration 1 --
90: array(2) {
91: [1]=>
92: int(1)
93: [2]=>
94: int(2)
95: }
96: -- Iteration 2 --
97: array(2) {
98: ["1.1"]=>
99: float(1.1)
100: ["2.2"]=>
101: float(2.2)
102: }
103: -- Iteration 3 --
104: array(2) {
105: [""]=>
106: bool(false)
107: [1]=>
108: bool(true)
109: }
110: -- Iteration 4 --
1.1.1.2 ! misho 111: array(0) {
! 112: }
1.1 misho 113: -- Iteration 5 --
114: array(1) {
115: [""]=>
116: NULL
117: }
118: -- Iteration 6 --
119: array(6) {
120: ["a"]=>
121: string(3) "a"
122: ["aaaa
"]=>
123: string(5) "aaaa
"
124: ["b"]=>
125: string(1) "b"
126: ["b bbb"]=>
127: string(5) "b bbb"
128: ["c"]=>
129: string(1) "c"
130: ["\[\]\!\@\#$\%\^\&\*\(\)\{\}"]=>
131: string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}"
132: }
133: -- Iteration 7 --
134: array(6) {
135: ["a\v\f"]=>
136: string(5) "a\v\f"
137: ["aaaa\r"]=>
138: string(6) "aaaa\r"
139: ["b"]=>
140: string(1) "b"
141: ["b\tbbb"]=>
142: string(6) "b\tbbb"
143: ["c"]=>
144: string(1) "c"
145: ["\[\]\!\@\#\$\%\^\&\*\(\)\{\}"]=>
146: string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"
147: }
148: -- Iteration 8 --
149: array(4) {
150: ["
151: "]=>
152: string(1) "
153: "
154: ["hello world
155: The quick brown fox jumped over;
156: the lazy dog
157: This is a double quoted string"]=>
158: string(88) "hello world
159: The quick brown fox jumped over;
160: the lazy dog
161: This is a double quoted string"
162: ["hello
world
163: 1111 != 2222
164: heredoc
165: double quoted string. withdifferentwhitespaces"]=>
166: string(88) "hello
world
167: 1111 != 2222
168: heredoc
169: double quoted string. withdifferentwhitespaces"
170: ["11 < 12. 123 >22
171: 'single quoted string'
172: "double quoted string"
173: 2222 != 1111. 0000 = 0000
174: "]=>
175: string(90) "11 < 12. 123 >22
176: 'single quoted string'
177: "double quoted string"
178: 2222 != 1111. 0000 = 0000
179: "
180: }
181: -- Iteration 9 --
182: array(3) {
183: ["one"]=>
184: string(3) "one"
185: ["two"]=>
186: string(3) "two"
187: ["three"]=>
188: string(5) "three"
189: }
190: -- Iteration 10 --
191: array(3) {
192: [1]=>
193: int(1)
194: [2]=>
195: int(2)
196: [3]=>
197: int(3)
198: }
199: -- Iteration 11 --
200: array(4) {
201: [10]=>
202: int(10)
203: [20]=>
204: int(20)
205: [40]=>
206: int(40)
207: [30]=>
208: int(30)
209: }
210: -- Iteration 12 --
211: array(3) {
212: ["ten"]=>
213: string(3) "ten"
214: ["twenty"]=>
215: string(6) "twenty"
216: ["thirty"]=>
217: string(6) "thirty"
218: }
219: -- Iteration 13 --
220: array(3) {
221: [1]=>
222: int(1)
223: ["two"]=>
224: string(3) "two"
225: ["four"]=>
226: string(4) "four"
227: }
228: -- Iteration 14 --
229: array(2) {
230: ["null"]=>
231: string(4) "null"
232: [""]=>
233: NULL
234: }
235: -- Iteration 15 --
236: array(4) {
237: ["true"]=>
238: string(4) "true"
239: ["false"]=>
240: string(5) "false"
241: [""]=>
242: bool(false)
243: [1]=>
244: bool(true)
245: }
246: -- Iteration 16 --
247: array(2) {
248: ["emptys"]=>
249: string(6) "emptys"
250: [""]=>
251: string(0) ""
252: }
253: -- Iteration 17 --
254: array(2) {
255: [""]=>
256: bool(false)
257: [1]=>
258: bool(true)
259: }
260: -- Iteration 18 --
261: array(3) {
262: [4]=>
263: int(4)
264: [5]=>
265: int(5)
266: [6]=>
267: int(6)
268: }
269: -- Iteration 19 --
270: array(3) {
271: [10]=>
272: int(10)
273: [20]=>
274: int(20)
275: [3]=>
276: int(3)
277: }
278: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>