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