1--TEST-- 2Test 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 16echo "*** 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 22EOT; 23 24// heredoc with multiline string 25$multiline_string = <<<EOT 26hello world 27The quick brown fox jumped over; 28the lazy dog 29This is a double quoted string 30EOT; 31 32// heredoc with different whitespaces 33$diff_whitespaces = <<<EOT 34hello\r world\t 351111\t\t != 2222\v\v 36heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces 37EOT; 38 39// heredoc with quoted strings and numeric values 40$numeric_string = <<<EOT 4111 < 12. 123 >22 42'single quoted string' 43"double quoted string" 442222 != 1111.\t 0000 = 0000\n 45EOT; 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; 79foreach($arrays as $array) { 80 echo "-- Iteration $iterator --\n"; 81 var_dump( array_combine($array, $array) ); 82 $iterator++; 83} 84 85echo "Done"; 86?> 87--EXPECTF-- 88*** Testing array_combine() : Passing different types of arrays to both $keys and $values argument *** 89-- Iteration 1 -- 90array(2) { 91 [1]=> 92 int(1) 93 [2]=> 94 int(2) 95} 96-- Iteration 2 -- 97array(2) { 98 ["1.1"]=> 99 float(1.1) 100 ["2.2"]=> 101 float(2.2) 102} 103-- Iteration 3 -- 104array(2) { 105 [""]=> 106 bool(false) 107 [1]=> 108 bool(true) 109} 110-- Iteration 4 -- 111array(0) { 112} 113-- Iteration 5 -- 114array(1) { 115 [""]=> 116 NULL 117} 118-- Iteration 6 -- 119array(6) { 120 ["a"]=> 121 string(3) "a" 122 ["aaaa 122"]=> 123 string(5) "aaaa 123" 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 -- 134array(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 -- 149array(4) { 150 [" 151"]=> 152 string(1) " 153" 154 ["hello world 155The quick brown fox jumped over; 156the lazy dog 157This is a double quoted string"]=> 158 string(88) "hello world 159The quick brown fox jumped over; 160the lazy dog 161This is a double quoted string" 162 ["hello 162 world 1631111 != 2222 164heredoc 165double quoted string. withdifferentwhitespaces"]=> 166 string(88) "hello 166 world 1671111 != 2222 168heredoc 169double quoted string. withdifferentwhitespaces" 170 ["11 < 12. 123 >22 171'single quoted string' 172"double quoted string" 1732222 != 1111. 0000 = 0000 174"]=> 175 string(90) "11 < 12. 123 >22 176'single quoted string' 177"double quoted string" 1782222 != 1111. 0000 = 0000 179" 180} 181-- Iteration 9 -- 182array(3) { 183 ["one"]=> 184 string(3) "one" 185 ["two"]=> 186 string(3) "two" 187 ["three"]=> 188 string(5) "three" 189} 190-- Iteration 10 -- 191array(3) { 192 [1]=> 193 int(1) 194 [2]=> 195 int(2) 196 [3]=> 197 int(3) 198} 199-- Iteration 11 -- 200array(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 -- 211array(3) { 212 ["ten"]=> 213 string(3) "ten" 214 ["twenty"]=> 215 string(6) "twenty" 216 ["thirty"]=> 217 string(6) "thirty" 218} 219-- Iteration 13 -- 220array(3) { 221 [1]=> 222 int(1) 223 ["two"]=> 224 string(3) "two" 225 ["four"]=> 226 string(4) "four" 227} 228-- Iteration 14 -- 229array(2) { 230 ["null"]=> 231 string(4) "null" 232 [""]=> 233 NULL 234} 235-- Iteration 15 -- 236array(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 -- 247array(2) { 248 ["emptys"]=> 249 string(6) "emptys" 250 [""]=> 251 string(0) "" 252} 253-- Iteration 17 -- 254array(2) { 255 [""]=> 256 bool(false) 257 [1]=> 258 bool(true) 259} 260-- Iteration 18 -- 261array(3) { 262 [4]=> 263 int(4) 264 [5]=> 265 int(5) 266 [6]=> 267 int(6) 268} 269-- Iteration 19 -- 270array(3) { 271 [10]=> 272 int(10) 273 [20]=> 274 int(20) 275 [3]=> 276 int(3) 277} 278Done 279