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 string keys 34/*7*/ array('\tHello' => 111, 're\td' => "color", 35 '\v\fworld' => 2.2, 'pen\n' => 33), 36 array("\tHello" => 111, "re\td" => "color", 37 "\v\fworld" => 2.2, "pen\n" => 33), 38 array("hello", $heredoc => "string"), // heredoc 39 40 // array with unset variable 41/*10*/ array( @$unset_var => "hello"), 42 43 // array with mixed keys 44/*11*/ array('hello' => 1, "fruit" => 2.2, 45 133 => "int", 46 @$unset_var => "unset", $heredoc => "heredoc") 47); 48 49// array to be passed to $arr2 argument 50$arr2 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11); 51 52// loop through each sub-array within $arrays to check the behavior of array_intersect() 53$iterator = 1; 54foreach($arrays as $arr1) { 55 echo "-- Iterator $iterator --\n"; 56 57 // Calling array_intersect() with default arguments 58 var_dump( array_intersect($arr1, $arr2) ); 59 60 // Calling array_intersect() with more arguments. 61 // additional argument passed is the same as $arr1 argument 62 var_dump( array_intersect($arr1, $arr2, $arr1) ); 63 $iterator++; 64} 65 66echo "Done"; 67?> 68--EXPECT-- 69*** Testing array_intersect() : assoc array with diff keys to $arr1 argument *** 70-- Iterator 1 -- 71array(0) { 72} 73array(0) { 74} 75-- Iterator 2 -- 76array(0) { 77} 78array(0) { 79} 80-- Iterator 3 -- 81array(1) { 82 [1]=> 83 string(1) "1" 84} 85array(1) { 86 [1]=> 87 string(1) "1" 88} 89-- Iterator 4 -- 90array(1) { 91 [1]=> 92 string(1) "1" 93} 94array(1) { 95 [1]=> 96 string(1) "1" 97} 98-- Iterator 5 -- 99array(2) { 100 ["re\td"]=> 101 string(5) "color" 102 ["\v\fworld"]=> 103 float(2.2) 104} 105array(2) { 106 ["re\td"]=> 107 string(5) "color" 108 ["\v\fworld"]=> 109 float(2.2) 110} 111-- Iterator 6 -- 112array(2) { 113 ["re d"]=> 114 string(5) "color" 115 ["world"]=> 116 float(2.2) 117} 118array(2) { 119 ["re d"]=> 120 string(5) "color" 121 ["world"]=> 122 float(2.2) 123} 124-- Iterator 7 -- 125array(2) { 126 [0]=> 127 string(5) "hello" 128 ["Hello world"]=> 129 string(6) "string" 130} 131array(2) { 132 [0]=> 133 string(5) "hello" 134 ["Hello world"]=> 135 string(6) "string" 136} 137-- Iterator 8 -- 138array(1) { 139 [""]=> 140 string(5) "hello" 141} 142array(1) { 143 [""]=> 144 string(5) "hello" 145} 146-- Iterator 9 -- 147array(2) { 148 ["hello"]=> 149 int(1) 150 ["fruit"]=> 151 float(2.2) 152} 153array(2) { 154 ["hello"]=> 155 int(1) 156 ["fruit"]=> 157 float(2.2) 158} 159Done 160