Annotation of embedaddon/php/ext/standard/tests/array/array_intersect_variation6.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_intersect() function : usage variations - assoc array with diff keys 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 keys to $arr2 argument.
13: * The $arr1 argument is a fixed array.
14: */
15:
16: echo "*** Testing array_intersect() : assoc array with diff keys to \$arr2 argument ***\n";
17:
18: // get an unset variable
19: $unset_var = 10;
20: unset ($unset_var);
21:
22: // get a heredoc string
23: $heredoc = <<<EOT
24: Hello world
25: EOT;
26:
27: // different variations of associative arrays to be passed to $arr2 argument
28: $arrays = array (
29:
30: // empty array
31: /*1*/ array(),
32:
33: // arrays with integer keys
34: array(0 => "0"),
35: array(1 => "1"),
36: array(1 => "1", 2 => "2", 3 => "3", 4 => "4"),
37:
38: // arrays with float keys
39: /*5*/ array(2.3333 => "float"),
40: array(1.2 => "f1", 3.33 => "f2",
41: 4.89999922839999 => "f3",
42: 33333333.333333 => "f4"),
43:
44: // arrays with string keys
45: /*7*/ array('\tHello' => 111, 're\td' => "color",
46: '\v\fworld' => 2.2, 'pen\n' => 33),
47: array("\tHello" => 111, "re\td" => "color",
48: "\v\fworld" => 2.2, "pen\n" => 33),
49: array("hello", $heredoc => "string"), // heredoc
50:
51: // array with unset variable
52: /*10*/ array( @$unset_var => "hello"),
53:
54: // array with mixed keys
55: /*11*/ array('hello' => 1, "fruit" => 2.2,
56: 133 => "int", 444.432 => "float",
57: @$unset_var => "unset", $heredoc => "heredoc")
58: );
59:
60: // array to be passsed to $arr1 argument
61: $arr1 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11);
62:
63: // loop through each sub-array within $arrrays to check the behavior of array_intersect()
64: $iterator = 1;
65: foreach($arrays as $arr2) {
66: echo "-- Iterator $iterator --\n";
67:
68: // Calling array_intersect() with default arguments
69: var_dump( array_intersect($arr1, $arr2) );
70:
71: // Calling array_intersect() with more arguments.
72: // additional argument passed is the same as $arr1 argument
73: var_dump( array_intersect($arr1, $arr2, $arr1) );
74: $iterator++;
75: }
76:
77: echo "Done";
78: ?>
79: --EXPECTF--
80: *** Testing array_intersect() : assoc array with diff keys to $arr2 argument ***
81: -- Iterator 1 --
82: array(0) {
83: }
84: array(0) {
85: }
86: -- Iterator 2 --
87: array(0) {
88: }
89: array(0) {
90: }
91: -- Iterator 3 --
92: array(1) {
93: [0]=>
94: int(1)
95: }
96: array(1) {
97: [0]=>
98: int(1)
99: }
100: -- Iterator 4 --
101: array(1) {
102: [0]=>
103: int(1)
104: }
105: array(1) {
106: [0]=>
107: int(1)
108: }
109: -- Iterator 5 --
110: array(1) {
111: [1]=>
112: string(5) "float"
113: }
114: array(1) {
115: [1]=>
116: string(5) "float"
117: }
118: -- Iterator 6 --
119: array(1) {
120: [2]=>
121: string(2) "f4"
122: }
123: array(1) {
124: [2]=>
125: string(2) "f4"
126: }
127: -- Iterator 7 --
128: array(2) {
129: [4]=>
130: float(2.2)
131: [5]=>
132: string(5) "color"
133: }
134: array(2) {
135: [4]=>
136: float(2.2)
137: [5]=>
138: string(5) "color"
139: }
140: -- Iterator 8 --
141: array(2) {
142: [4]=>
143: float(2.2)
144: [5]=>
145: string(5) "color"
146: }
147: array(2) {
148: [4]=>
149: float(2.2)
150: [5]=>
151: string(5) "color"
152: }
153: -- Iterator 9 --
154: array(2) {
155: [3]=>
156: string(5) "hello"
157: [6]=>
158: string(6) "string"
159: }
160: array(2) {
161: [3]=>
162: string(5) "hello"
163: [6]=>
164: string(6) "string"
165: }
166: -- Iterator 10 --
167: array(1) {
168: [3]=>
169: string(5) "hello"
170: }
171: array(1) {
172: [3]=>
173: string(5) "hello"
174: }
175: -- Iterator 11 --
176: array(3) {
177: [0]=>
178: int(1)
179: [1]=>
180: string(5) "float"
181: [4]=>
182: float(2.2)
183: }
184: array(3) {
185: [0]=>
186: int(1)
187: [1]=>
188: string(5) "float"
189: [4]=>
190: float(2.2)
191: }
192: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>