2 Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr1' argument
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
12 * Testing the functionality of array_intersect_assoc() by passing different
13 * associative arrays having different possible values to $arr1 argument.
14 * The $arr2 argument passed is a fixed array
17 echo "*** Testing array_intersect_assoc() : assoc array with diff values to \$arr1 argument ***\n";
19 // get an unset variable
23 // get a resource variable
24 $fp = fopen(__FILE__, "r");
29 public function __toString(){
30 return "Class A object";
34 // get a heredoc string
39 // different variations of associative arrays to be passed to $arr1 argument
45 // arrays with integer values
48 array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
50 // arrays with float values
51 /*5*/ array("float" => 2.3333),
52 array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333),
54 // arrays with string values
55 /*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"),
56 array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'),
57 array(1 => "hello", "heredoc" => $heredoc),
59 // array with object, unset variable and resource variable
60 /*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
62 // array with mixed values
63 /*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit",
64 'resource' => $fp, "int" => 133, "float" => 444.432,
65 "unset" => @$unset_var, "heredoc" => $heredoc)
68 // array to be passsed to $arr2 argument
69 $arr2 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2,
70 "f4" => 33333333.333, 111 => "\tHello", 3.3 => 'pen\n', '\v\fworld',
71 "heredoc" => "Hello world", 11 => new classA(), "resource" => $fp,
72 "int" => 133, 222 => "fruit");
74 // loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
76 foreach($arrays as $arr1) {
77 echo "-- Iteration $iterator --\n";
79 // Calling array_intersect_assoc() with default arguments
80 var_dump( array_intersect_assoc($arr1, $arr2) );
82 // Calling array_intersect_assoc() with more arguments.
83 // additional argument passed is the same as $arr1 argument
84 var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
88 // close the file resource used
94 *** Testing array_intersect_assoc() : assoc array with diff values to $arr1 argument ***
170 string(11) "Hello world"
174 string(11) "Hello world"
179 object(classA)#%d (0) {
182 resource(%d) of type (stream)
186 object(classA)#%d (0) {
189 resource(%d) of type (stream)
196 resource(%d) of type (stream)
200 string(11) "Hello world"
206 resource(%d) of type (stream)
210 string(11) "Hello world"