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