1--TEST-- 2Test array_combine() function : usage variations - associative array with different values(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* Testing the functionality of array_combine() by passing various 13* associative arrays having different possible values to $keys argument and 14* associative arrays having different possible values to $values argument. 15*/ 16 17echo "*** Testing array_combine() : assoc array with diff values to both \$keys and \$values argument ***\n"; 18 19// get an unset variable 20$unset_var = 10; 21unset ($unset_var); 22 23// get a resource variable 24$fp = fopen(__FILE__, "r"); 25 26// get a class 27class classA 28{ 29public function __toString(){ 30return "Class A object"; 31} 32} 33 34// get a heredoc string 35$heredoc = <<<EOT 36Hello world 37EOT; 38 39// different variations of associative array 40$arrays = array ( 41 42 // empty array 43/*1*/ array(), 44 45 // arrays with integer values 46 array('0' => 0), 47 array("1" => 1), 48 array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), 49 50 // arrays with float values 51/*5*/ array("float" => 2.3333), 52 array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), 53 54 // arrays with string values 55/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), 56 array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), 57 array(1 => "hello", "heredoc" => $heredoc), 58 59 // array with object, unset variable and resource variable 60/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), 61 62 // array with mixed values 63/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 64 'resource' => $fp, "int" => 133, "float" => 444.432, 65 "unset" => @$unset_var, "heredoc" => $heredoc) 66); 67 68 69// loop through each sub-array within $arrays to check the behavior of array_combine() 70$iterator = 1; 71foreach($arrays as $array) { 72 echo "-- Iteration $iterator --\n"; 73 var_dump( array_combine($array, $array) ); 74 $iterator++; 75} 76 77// close the file resource used 78fclose($fp); 79 80echo "Done"; 81?> 82--EXPECTF-- 83*** Testing array_combine() : assoc array with diff values to both $keys and $values argument *** 84-- Iteration 1 -- 85array(0) { 86} 87-- Iteration 2 -- 88array(1) { 89 [0]=> 90 int(0) 91} 92-- Iteration 3 -- 93array(1) { 94 [1]=> 95 int(1) 96} 97-- Iteration 4 -- 98array(4) { 99 [1]=> 100 int(1) 101 [2]=> 102 int(2) 103 [3]=> 104 int(3) 105 [4]=> 106 int(4) 107} 108-- Iteration 5 -- 109array(1) { 110 ["2.3333"]=> 111 float(2.3333) 112} 113-- Iteration 6 -- 114array(4) { 115 ["1.2"]=> 116 float(1.2) 117 ["3.33"]=> 118 float(3.33) 119 ["4.8999992284"]=> 120 float(4.8999992284) 121 ["33333333.333"]=> 122 float(33333333.333) 123} 124-- Iteration 7 -- 125array(4) { 126 [" Hello"]=> 127 string(6) " Hello" 128 ["col or"]=> 129 string(6) "col or" 130 ["world"]=> 131 string(7) "world" 132 ["pen 133"]=> 134 string(4) "pen 135" 136} 137-- Iteration 8 -- 138array(4) { 139 ["\tHello"]=> 140 string(7) "\tHello" 141 ["col\tor"]=> 142 string(7) "col\tor" 143 ["\v\fworld"]=> 144 string(9) "\v\fworld" 145 ["pen\n"]=> 146 string(5) "pen\n" 147} 148-- Iteration 9 -- 149array(2) { 150 ["hello"]=> 151 string(5) "hello" 152 ["Hello world"]=> 153 string(11) "Hello world" 154} 155-- Iteration 10 -- 156array(3) { 157 ["Class A object"]=> 158 object(classA)#%d (0) { 159 } 160 [""]=> 161 NULL 162 ["Resource id #%d"]=> 163 resource(%d) of type (stream) 164} 165-- Iteration 11 -- 166array(8) { 167 ["hello"]=> 168 string(5) "hello" 169 ["Class A object"]=> 170 object(classA)#%d (0) { 171 } 172 ["fruit"]=> 173 string(5) "fruit" 174 ["Resource id #%d"]=> 175 resource(%d) of type (stream) 176 [133]=> 177 int(133) 178 ["444.432"]=> 179 float(444.432) 180 [""]=> 181 NULL 182 ["Hello world"]=> 183 string(11) "Hello world" 184} 185Done 186