1--TEST-- 2Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr1' argument 3--FILE-- 4<?php 5/* 6 * Testing the functionality of array_intersect_assoc() by passing different 7 * associative arrays having different possible keys to $arr1 argument. 8 * The $arr2 argument passed is a fixed array 9*/ 10 11echo "*** Testing array_intersect_assoc() : 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 object, unset variable and resource 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(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", 57 "\tHello" => 111, 2.2, 'color', "Hello world" => "string", 58 "pen\n" => 33, 133 => "int"); 59 60// loop through each sub-array within $arrays to check the behavior of array_intersect_assoc() 61$iterator = 1; 62foreach($arrays as $arr1) { 63 echo "-- Iteration $iterator --\n"; 64 65 // Calling array_intersect_assoc() with default arguments 66 var_dump( array_intersect_assoc($arr1, $arr2) ); 67 68 // Calling array_intersect_assoc() with more arguments. 69 // additional argument passed is the same as $arr1 argument 70 var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); 71 $iterator++; 72} 73 74echo "Done"; 75?> 76--EXPECT-- 77*** Testing array_intersect_assoc() : assoc array with diff keys to $arr1 argument *** 78-- Iteration 1 -- 79array(0) { 80} 81array(0) { 82} 83-- Iteration 2 -- 84array(1) { 85 [0]=> 86 string(1) "0" 87} 88array(1) { 89 [0]=> 90 string(1) "0" 91} 92-- Iteration 3 -- 93array(0) { 94} 95array(0) { 96} 97-- Iteration 4 -- 98array(0) { 99} 100array(0) { 101} 102-- Iteration 5 -- 103array(1) { 104 [2]=> 105 string(5) "float" 106} 107array(1) { 108 [2]=> 109 string(5) "float" 110} 111-- Iteration 6 -- 112array(2) { 113 [4]=> 114 string(2) "f3" 115 [33333333]=> 116 string(2) "f4" 117} 118array(2) { 119 [4]=> 120 string(2) "f3" 121 [33333333]=> 122 string(2) "f4" 123} 124-- Iteration 7 -- 125array(0) { 126} 127array(0) { 128} 129-- Iteration 8 -- 130array(2) { 131 [" Hello"]=> 132 int(111) 133 ["pen 134"]=> 135 int(33) 136} 137array(2) { 138 [" Hello"]=> 139 int(111) 140 ["pen 141"]=> 142 int(33) 143} 144-- Iteration 9 -- 145array(1) { 146 ["Hello world"]=> 147 string(6) "string" 148} 149array(1) { 150 ["Hello world"]=> 151 string(6) "string" 152} 153-- Iteration 10 -- 154array(0) { 155} 156array(0) { 157} 158-- Iteration 11 -- 159array(1) { 160 [133]=> 161 string(3) "int" 162} 163array(1) { 164 [133]=> 165 string(3) "int" 166} 167Done 168