1--TEST-- 2Test array_intersect() function : usage variations - assoc array with diff keys for 'arr1' argument 3--FILE-- 4<?php 5/* 6 * Testing the functionality of array_intersect() by passing different 7 * associative arrays having different possible keys to $arr1 argument. 8 * The $arr2 argument is a fixed array 9*/ 10 11echo "*** Testing array_intersect() : assoc array with diff keys to \$arr1 argument ***\n"; 12 13// get an unset variable 14$unset_var = 10; 15unset ($unset_var); 16 17// get a heredoc string 18$heredoc = <<<EOT 19Hello world 20EOT; 21 22// different variations of associative arrays to be passed to $arr1 argument 23$arrays = array ( 24 25 // empty array 26/*1*/ array(), 27 28 // arrays with integer keys 29 array(0 => "0"), 30 array(1 => "1"), 31 array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), 32 33 // arrays with float keys 34/*5*/ array(2.3333 => "float"), 35 array(1.2 => "f1", 3.33 => "f2", 36 4.89999922839999 => "f3", 37 33333333.333333 => "f4"), 38 39 // arrays with string keys 40/*7*/ array('\tHello' => 111, 're\td' => "color", 41 '\v\fworld' => 2.2, 'pen\n' => 33), 42 array("\tHello" => 111, "re\td" => "color", 43 "\v\fworld" => 2.2, "pen\n" => 33), 44 array("hello", $heredoc => "string"), // heredoc 45 46 // array with unset variable 47/*10*/ array( @$unset_var => "hello"), 48 49 // array with mixed keys 50/*11*/ array('hello' => 1, "fruit" => 2.2, 51 133 => "int", 444.432 => "float", 52 @$unset_var => "unset", $heredoc => "heredoc") 53); 54 55// array to be passsed to $arr2 argument 56$arr2 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11); 57 58// loop through each sub-array within $arrays to check the behavior of array_intersect() 59$iterator = 1; 60foreach($arrays as $arr1) { 61 echo "-- Iterator $iterator --\n"; 62 63 // Calling array_intersect() with default arguments 64 var_dump( array_intersect($arr1, $arr2) ); 65 66 // Calling array_intersect() with more arguments. 67 // additional argument passed is the same as $arr1 argument 68 var_dump( array_intersect($arr1, $arr2, $arr1) ); 69 $iterator++; 70} 71 72echo "Done"; 73?> 74--EXPECT-- 75*** Testing array_intersect() : assoc array with diff keys to $arr1 argument *** 76-- Iterator 1 -- 77array(0) { 78} 79array(0) { 80} 81-- Iterator 2 -- 82array(0) { 83} 84array(0) { 85} 86-- Iterator 3 -- 87array(1) { 88 [1]=> 89 string(1) "1" 90} 91array(1) { 92 [1]=> 93 string(1) "1" 94} 95-- Iterator 4 -- 96array(1) { 97 [1]=> 98 string(1) "1" 99} 100array(1) { 101 [1]=> 102 string(1) "1" 103} 104-- Iterator 5 -- 105array(1) { 106 [2]=> 107 string(5) "float" 108} 109array(1) { 110 [2]=> 111 string(5) "float" 112} 113-- Iterator 6 -- 114array(1) { 115 [33333333]=> 116 string(2) "f4" 117} 118array(1) { 119 [33333333]=> 120 string(2) "f4" 121} 122-- Iterator 7 -- 123array(2) { 124 ["re\td"]=> 125 string(5) "color" 126 ["\v\fworld"]=> 127 float(2.2) 128} 129array(2) { 130 ["re\td"]=> 131 string(5) "color" 132 ["\v\fworld"]=> 133 float(2.2) 134} 135-- Iterator 8 -- 136array(2) { 137 ["re d"]=> 138 string(5) "color" 139 ["world"]=> 140 float(2.2) 141} 142array(2) { 143 ["re d"]=> 144 string(5) "color" 145 ["world"]=> 146 float(2.2) 147} 148-- Iterator 9 -- 149array(2) { 150 [0]=> 151 string(5) "hello" 152 ["Hello world"]=> 153 string(6) "string" 154} 155array(2) { 156 [0]=> 157 string(5) "hello" 158 ["Hello world"]=> 159 string(6) "string" 160} 161-- Iterator 10 -- 162array(1) { 163 [""]=> 164 string(5) "hello" 165} 166array(1) { 167 [""]=> 168 string(5) "hello" 169} 170-- Iterator 11 -- 171array(3) { 172 ["hello"]=> 173 int(1) 174 ["fruit"]=> 175 float(2.2) 176 [444]=> 177 string(5) "float" 178} 179array(3) { 180 ["hello"]=> 181 int(1) 182 ["fruit"]=> 183 float(2.2) 184 [444]=> 185 string(5) "float" 186} 187Done 188