Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / php / ext / standard / tests / array / array_intersect_assoc_variation7.phpt
blobba2f79a7ecb1326d093c0da1d033cdc42a9d185b
1 --TEST--
2 Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr1' 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 */
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
20 $unset_var = 10;
21 unset ($unset_var);
23 // get a resource variable
24 $fp = fopen(__FILE__, "r");
26 // get a class
27 class classA
29   public function __toString(){
30     return "Class A object";
31   }
34 // get a heredoc string
35 $heredoc = <<<EOT
36 Hello world
37 EOT;
39 // different variations of associative arrays to be passed to $arr1 argument
40 $arrays = array (
42        // empty array
43 /*1*/  array(),
45        // arrays with integer values
46        array('0' => 0),
47        array("1" => 1),
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()
75 $iterator = 1;
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) );
85   $iterator++;
88 // close the file resource used
89 fclose($fp);
91 echo "Done";
93 --EXPECTF--
94 *** Testing array_intersect_assoc() : assoc array with diff values to $arr1 argument ***
95 -- Iteration 1 --
96 array(0) {
98 array(0) {
100 -- Iteration 2 --
101 array(1) {
102   [0]=>
103   int(0)
105 array(1) {
106   [0]=>
107   int(0)
109 -- Iteration 3 --
110 array(1) {
111   [1]=>
112   int(1)
114 array(1) {
115   [1]=>
116   int(1)
118 -- Iteration 4 --
119 array(1) {
120   ["two"]=>
121   int(2)
123 array(1) {
124   ["two"]=>
125   int(2)
127 -- Iteration 5 --
128 array(1) {
129   ["float"]=>
130   float(2.3333)
132 array(1) {
133   ["float"]=>
134   float(2.3333)
136 -- Iteration 6 --
137 array(2) {
138   ["f1"]=>
139   float(1.2)
140   ["f4"]=>
141   float(33333333.333)
143 array(2) {
144   ["f1"]=>
145   float(1.2)
146   ["f4"]=>
147   float(33333333.333)
149 -- Iteration 7 --
150 array(1) {
151   [111]=>
152   string(6) "   Hello"
154 array(1) {
155   [111]=>
156   string(6) "   Hello"
158 -- Iteration 8 --
159 array(1) {
160   [3]=>
161   string(5) "pen\n"
163 array(1) {
164   [3]=>
165   string(5) "pen\n"
167 -- Iteration 9 --
168 array(1) {
169   ["heredoc"]=>
170   string(11) "Hello world"
172 array(1) {
173   ["heredoc"]=>
174   string(11) "Hello world"
176 -- Iteration 10 --
177 array(2) {
178   [11]=>
179   object(classA)#%d (0) {
180   }
181   ["resource"]=>
182   resource(%d) of type (stream)
184 array(2) {
185   [11]=>
186   object(classA)#%d (0) {
187   }
188   ["resource"]=>
189   resource(%d) of type (stream)
191 -- Iteration 11 --
192 array(4) {
193   [222]=>
194   string(5) "fruit"
195   ["resource"]=>
196   resource(%d) of type (stream)
197   ["int"]=>
198   int(133)
199   ["heredoc"]=>
200   string(11) "Hello world"
202 array(4) {
203   [222]=>
204   string(5) "fruit"
205   ["resource"]=>
206   resource(%d) of type (stream)
207   ["int"]=>
208   int(133)
209   ["heredoc"]=>
210   string(11) "Hello world"
212 Done