import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-array / array_intersect_assoc_variation6.php
blob6fcd6d7ad65878da61540d8a66c0f775888f1e29
1 <?php
2 /* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...])
3 * Description: Returns the entries of arr1 that have values which are present in all the other arguments.
4 * Keys are used to do more restrictive check
5 * Source code: ext/standard/array.c
6 */
8 /*
9 * Testing the functionality of array_intersect_assoc() by passing different
10 * associative arrays having different possible keys to $arr2 argument.
11 * The $arr1 argument passed is a fixed array.
14 echo "*** Testing array_intersect_assoc() : assoc array with diff keys to \$arr2 argument ***\n";
16 // get an unset variable
17 $unset_var = 10;
18 unset ($unset_var);
20 // get a heredoc string
21 $heredoc = <<<EOT
22 Hello world
23 EOT;
25 // different variations of associative arrays to be passed to $arr2 argument
26 $arrays = array (
28 // empty array
29 /*1*/ array(),
31 // arrays with integer keys
32 array(0 => "0"),
33 array(1 => "1"),
34 array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
36 // arrays with float keys
37 /*5*/ array(2.3333 => "float"),
38 array(1.2 => "f1", 3.33 => "f2",
39 4.89999922839999 => "f3",
40 33333333.333333 => "f4"),
42 // arrays with string keys
43 /*7*/ array('\tHello' => 111, 're\td' => "color",
44 '\v\fworld' => 2.2, 'pen\n' => 33),
45 array("\tHello" => 111, "re\td" => "color",
46 "\v\fworld" => 2.2, "pen\n" => 33),
47 array("hello", $heredoc => "string"), // heredoc
49 // array with unset variable
50 /*10*/ array( @$unset_var => "hello"),
52 // array with mixed keys
53 /*11*/ array('hello' => 1, "fruit" => 2.2,
54 133 => "int", 444.432 => "float",
55 @$unset_var => "unset", $heredoc => "heredoc")
58 // array to be passsed to $arr1 argument
59 $arr1 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4",
60 "\tHello" => 111, 2.2, 'color', "Hello world" => "string",
61 "pen\n" => 33, 133 => "int");
63 // loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
64 $iterator = 1;
65 foreach($arrays as $arr2) {
66 echo "-- Iteration $iterator --\n";
68 // Calling array_intersect_assoc() with default arguments
69 var_dump( array_intersect_assoc($arr1, $arr2) );
71 // Calling array_intersect_assoc() with more arguments.
72 // additional argument passed is the same as $arr1 argument
73 var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
74 $iterator++;
77 echo "Done";