Annotation of embedaddon/php/ext/standard/tests/array/array_intersect_variation8.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_intersect() function : usage variations - assoc array with diff values for 'arr2' argument
3: --FILE--
4: <?php
5: /* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...])
6: * Description: Returns the entries of arr1 that have values which are present in all the other arguments
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Testing the functionality of array_intersect() by passing different
12: * associative arrays having different possible values to $arr2 argument.
13: * The $arr1 argument is a fixed array.
14: */
15:
16: echo "*** Testing array_intersect() : assoc array with diff values to \$arr2 argument ***\n";
17:
18: // get an unset variable
19: $unset_var = 10;
20: unset ($unset_var);
21:
22: // get a resource variable
23: $fp = fopen(__FILE__, "r");
24:
25: // get a class
26: class classA
27: {
28: public function __toString(){
29: return "Class A object";
30: }
31: }
32:
33: // get a heredoc string
34: $heredoc = <<<EOT
35: Hello world
36: EOT;
37:
38: // different variations of associative arrays to be passed to $arr2 argument
39: $arrays = array (
40:
41: // empty array
42: /*1*/ array(),
43:
44: // arrays with integer values
45: array('0' => 0),
46: array("1" => 1),
47: array("one" => 1, 'two' => 2, "three" => 3, 4 => 4),
48:
49: // arrays with float values
50: /*5*/ array("float" => 2.3333),
51: array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333),
52:
53: // arrays with string values
54: /*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"),
55: array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'),
56: array(1 => "hello", "heredoc" => $heredoc),
57:
58: // array with object, unset variable and resource variable
59: /*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp),
60:
61: // array with mixed values
62: /*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit",
63: 'resource' => $fp, "int" => 133, "float" => 444.432,
64: "unset" => @$unset_var, "heredoc" => $heredoc)
65: );
66:
67: // array to be passsed to $arr1 argument
68: $arr1 = array(1, 2, 1.2, 2.3333, "col\tor", '\v\fworld', $fp,
69: "Hello world", $heredoc, new classA(), 444.432, "fruit");
70:
71: // loop through each sub-array within $arrrays to check the behavior of array_intersect()
72: $iterator = 1;
73: foreach($arrays as $arr2) {
74: echo "-- Iterator $iterator --\n";
75:
76: // Calling array_intersect() with default arguments
77: var_dump( array_intersect($arr1, $arr2) );
78:
79: // Calling array_intersect() with more arguments.
80: // additional argument passed is the same as $arr1 argument
81: var_dump( array_intersect($arr1, $arr2, $arr1) );
82: $iterator++;
83: }
84:
85: // close the file resource used
86: fclose($fp);
87:
88: echo "Done";
89: ?>
90: --EXPECTF--
91: *** Testing array_intersect() : assoc array with diff values to $arr2 argument ***
92: -- Iterator 1 --
93: array(0) {
94: }
95: array(0) {
96: }
97: -- Iterator 2 --
98: array(0) {
99: }
100: array(0) {
101: }
102: -- Iterator 3 --
103: array(1) {
104: [0]=>
105: int(1)
106: }
107: array(1) {
108: [0]=>
109: int(1)
110: }
111: -- Iterator 4 --
112: array(2) {
113: [0]=>
114: int(1)
115: [1]=>
116: int(2)
117: }
118: array(2) {
119: [0]=>
120: int(1)
121: [1]=>
122: int(2)
123: }
124: -- Iterator 5 --
125: array(1) {
126: [3]=>
127: float(2.3333)
128: }
129: array(1) {
130: [3]=>
131: float(2.3333)
132: }
133: -- Iterator 6 --
134: array(1) {
135: [2]=>
136: float(1.2)
137: }
138: array(1) {
139: [2]=>
140: float(1.2)
141: }
142: -- Iterator 7 --
143: array(1) {
144: [4]=>
145: string(6) "col or"
146: }
147: array(1) {
148: [4]=>
149: string(6) "col or"
150: }
151: -- Iterator 8 --
152: array(1) {
153: [5]=>
154: string(9) "\v\fworld"
155: }
156: array(1) {
157: [5]=>
158: string(9) "\v\fworld"
159: }
160: -- Iterator 9 --
161: array(2) {
162: [7]=>
163: string(11) "Hello world"
164: [8]=>
165: string(11) "Hello world"
166: }
167: array(2) {
168: [7]=>
169: string(11) "Hello world"
170: [8]=>
171: string(11) "Hello world"
172: }
173: -- Iterator 10 --
174: array(2) {
175: [6]=>
176: resource(%d) of type (stream)
177: [9]=>
178: object(classA)#%d (0) {
179: }
180: }
181: array(2) {
182: [6]=>
183: resource(%d) of type (stream)
184: [9]=>
185: object(classA)#%d (0) {
186: }
187: }
188: -- Iterator 11 --
189: array(6) {
190: [6]=>
191: resource(%d) of type (stream)
192: [7]=>
193: string(11) "Hello world"
194: [8]=>
195: string(11) "Hello world"
196: [9]=>
197: object(classA)#%d (0) {
198: }
199: [10]=>
200: float(444.432)
201: [11]=>
202: string(5) "fruit"
203: }
204: array(6) {
205: [6]=>
206: resource(%d) of type (stream)
207: [7]=>
208: string(11) "Hello world"
209: [8]=>
210: string(11) "Hello world"
211: [9]=>
212: object(classA)#%d (0) {
213: }
214: [10]=>
215: float(444.432)
216: [11]=>
217: string(5) "fruit"
218: }
219: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>