1--TEST-- 2Test array_intersect() function : usage variations - assoc array with diff keys for 'arr2' argument 3--FILE-- 4<?php 5/* 6 * Testing the functionality of array_intersect() by passing different 7 * associative arrays having different possible keys to $arr2 argument. 8 * The $arr1 argument is a fixed array. 9*/ 10 11echo "*** Testing array_intersect() : assoc array with diff keys to \$arr2 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 $arr2 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 $arr1 argument 50$arr1 = 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 $arr2) { 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 $arr2 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 [0]=> 83 int(1) 84} 85array(1) { 86 [0]=> 87 int(1) 88} 89-- Iterator 4 -- 90array(1) { 91 [0]=> 92 int(1) 93} 94array(1) { 95 [0]=> 96 int(1) 97} 98-- Iterator 5 -- 99array(2) { 100 [4]=> 101 float(2.2) 102 [5]=> 103 string(5) "color" 104} 105array(2) { 106 [4]=> 107 float(2.2) 108 [5]=> 109 string(5) "color" 110} 111-- Iterator 6 -- 112array(2) { 113 [4]=> 114 float(2.2) 115 [5]=> 116 string(5) "color" 117} 118array(2) { 119 [4]=> 120 float(2.2) 121 [5]=> 122 string(5) "color" 123} 124-- Iterator 7 -- 125array(2) { 126 [3]=> 127 string(5) "hello" 128 [6]=> 129 string(6) "string" 130} 131array(2) { 132 [3]=> 133 string(5) "hello" 134 [6]=> 135 string(6) "string" 136} 137-- Iterator 8 -- 138array(1) { 139 [3]=> 140 string(5) "hello" 141} 142array(1) { 143 [3]=> 144 string(5) "hello" 145} 146-- Iterator 9 -- 147array(2) { 148 [0]=> 149 int(1) 150 [4]=> 151 float(2.2) 152} 153array(2) { 154 [0]=> 155 int(1) 156 [4]=> 157 float(2.2) 158} 159Done 160