Annotation of embedaddon/php/ext/standard/tests/array/array_intersect_assoc_variation3.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test array_intersect_assoc() function : usage variations - different arrays 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: */
10:
11: /*
12: * Passing different types of arrays to $arr1 argument and testing whether
13: * array_intersect_assoc() behaves in an expected way with the other arguments passed to the function
14: * The $arr2 argument passed is a fixed array.
15: */
16:
17: echo "*** Testing array_intersect_assoc() : Passing different types of arrays to \$arr1 argument ***\n";
18:
19: /* Different heredoc strings passed as argument to $arr1 */
20: // heredoc with blank line
21: $blank_line = <<<EOT
22:
23:
24: EOT;
25:
26: // heredoc with multiline string
27: $multiline_string = <<<EOT
28: hello world
29: The big brown fox jumped over;
30: the lazy dog
31: This is a double quoted string
32: EOT;
33:
1.1.1.2 ! misho 34: // heredoc with different whitespaces
1.1 misho 35: $diff_whitespaces = <<<EOT
36: hello\r world\t
37: 1111\t\t != 2222\v\v
38: heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
39: EOT;
40:
41: // heredoc with quoted strings and numeric values
42: $numeric_string = <<<EOT
43: 11 < 12. 123 >22
44: 'single quoted string'
45: "double quoted string"
46: 2222 != 1111.\t 0000 = 0000\n
47: EOT;
48:
49: // arrays to be passed to $arr1 argument
50: $arrays = array (
51: /*1*/ array(1, 2), // with default keys and numeric values
52: array(1.1, 2.2), // with default keys & float values
53: array(false,true), // with default keys and boolean values
54: array(), // empty array
55: /*5*/ array(NULL), // with NULL
56: array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings
57: array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings
58: array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs
59:
60: // associative arrays
61: /*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values
62: array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values
63: array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values
64: array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value
65: array("one" => 1, 2 => "two", 4 => "four"), //mixed
66:
67: // associative array, containing null/empty/boolean values as key/value
68: /*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null),
69: array(true => "true", false => "false", "false" => false, "true" => true),
70: array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''),
71: array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true),
72: array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6),
73:
74: // array with repetative keys
75: /*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3)
76: );
77:
78:
79: // array to be passsed to $arr2 argument
80: $arr2 = array (
81: 1, 1.1, 2.2, "hello", "one", NULL, 2,
82: 'world', true,5 => false, 1 => 'aaaa\r', "aaaa\r",
83: 'h3' => $diff_whitespaces, $numeric_string,
84: "one" => "ten", 4 => "four", "two" => 2,
85: '', null => "null", '' => 'emptys', "emptyd" => "",
86: );
87:
88: // loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc()
89: $iterator = 1;
90: foreach($arrays as $arr1) {
91: echo "-- Iteration $iterator --\n";
92:
93: // Calling array_intersect_assoc() with default arguments
94: var_dump( array_intersect_assoc($arr1, $arr2) );
95:
96: // Calling array_intersect_assoc() with more arguments.
97: // additional argument passed is the same as $arr1 argument
98: var_dump( array_intersect_assoc($arr1, $arr2, $arr1) );
99: $iterator++;
100: }
101:
102: echo "Done";
103: ?>
104: --EXPECTF--
105: *** Testing array_intersect_assoc() : Passing different types of arrays to $arr1 argument ***
106: -- Iteration 1 --
107: array(1) {
108: [0]=>
109: int(1)
110: }
111: array(1) {
112: [0]=>
113: int(1)
114: }
115: -- Iteration 2 --
116: array(0) {
117: }
118: array(0) {
119: }
120: -- Iteration 3 --
121: array(0) {
122: }
123: array(0) {
124: }
125: -- Iteration 4 --
126: array(0) {
127: }
128: array(0) {
129: }
130: -- Iteration 5 --
131: array(0) {
132: }
133: array(0) {
134: }
135: -- Iteration 6 --
136: array(0) {
137: }
138: array(0) {
139: }
140: -- Iteration 7 --
141: array(1) {
142: [1]=>
143: string(6) "aaaa\r"
144: }
145: array(1) {
146: [1]=>
147: string(6) "aaaa\r"
148: }
149: -- Iteration 8 --
150: array(1) {
151: ["h3"]=>
152: string(88) "hello
world
153: 1111 != 2222
154: heredoc
155: double quoted string. withdifferentwhitespaces"
156: }
157: array(1) {
158: ["h3"]=>
159: string(88) "hello
world
160: 1111 != 2222
161: heredoc
162: double quoted string. withdifferentwhitespaces"
163: }
164: -- Iteration 9 --
165: array(0) {
166: }
167: array(0) {
168: }
169: -- Iteration 10 --
170: array(1) {
171: ["two"]=>
172: int(2)
173: }
174: array(1) {
175: ["two"]=>
176: int(2)
177: }
178: -- Iteration 11 --
179: array(0) {
180: }
181: array(0) {
182: }
183: -- Iteration 12 --
184: array(1) {
185: ["one"]=>
186: string(3) "ten"
187: }
188: array(1) {
189: ["one"]=>
190: string(3) "ten"
191: }
192: -- Iteration 13 --
193: array(1) {
194: [4]=>
195: string(4) "four"
196: }
197: array(1) {
198: [4]=>
199: string(4) "four"
200: }
201: -- Iteration 14 --
202: array(0) {
203: }
204: array(0) {
205: }
206: -- Iteration 15 --
207: array(0) {
208: }
209: array(0) {
210: }
211: -- Iteration 16 --
212: array(2) {
213: [""]=>
214: string(6) "emptys"
215: ["emptyd"]=>
216: string(0) ""
217: }
218: array(2) {
219: [""]=>
220: string(6) "emptys"
221: ["emptyd"]=>
222: string(0) ""
223: }
224: -- Iteration 17 --
225: array(1) {
226: [5]=>
227: bool(false)
228: }
229: array(1) {
230: [5]=>
231: bool(false)
232: }
233: -- Iteration 18 --
234: array(0) {
235: }
236: array(0) {
237: }
238: -- Iteration 19 --
239: array(0) {
240: }
241: array(0) {
242: }
243: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>