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