Annotation of embedaddon/php/ext/standard/tests/array/array_merge.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_merge() function
3: --INI--
4: precision=14
5: --FILE--
6: <?php
7: /* Prototype: array array_merge(array $array1 [, array $array2 [, array $...]]);
8: Description: Merge one or more arrays
9: */
10:
11: echo "\n*** Testing array_merge() basic functionality ***";
12: $begin_array = array(
13: array(),
14: array( 1 => "string"),
15: array( "" => "string"),
16: array( -2.44444 => 12),
17: array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344),
18: array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL,1 => -2.344),
19: array( NULL, 1.23 => "Hi", "string" => "hello",
20: array("" => "World", "-2.34" => "a", "0" => "b"))
21: );
22:
23: $end_array = array(
24: array(),
25: array( 1 => "string"),
26: array( "" => "string"),
27: array( -2.44444 => 12),
28: array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344),
29: array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, 1=> -2.344),
30: array( NULL, 1.23 => "Hi", "string" => "hello",
31: array("" => "World", "-2.34" => "a", "0" => "b"))
32: );
33:
34: /* loop through to merge two arrays */
35: $count_outer = 0;
36: foreach($begin_array as $first) {
37: echo "\n\n--- Iteration $count_outer ---";
38: $count_inner = 0;
39: foreach($end_array as $second) {
40: echo "\n-- Inner iteration $count_inner of Iteration $count_outer --\n";
41: $result = array_merge($first, $second);
42: print_r($result);
43: $count_inner++;
44: }
45: $count_outer++;
46: }
47:
48:
49: echo "\n*** Testing array_merge() with three or more arrays ***\n";
50: var_dump( array_merge( $end_array[0],
51: $end_array[5],
52: $end_array[4],
53: $end_array[6]
54: )
55: );
56:
57: var_dump( array_merge( $end_array[0],
58: $end_array[5],
59: array("array on fly"),
60: array("nullarray" => array())
61: )
62: );
63:
64:
65: echo "\n*** Testing single array argument ***\n";
66: /* Empty array */
67: var_dump(array_merge(array()));
68:
69: /* associative array with string keys, which will not be re-indexed */
70: var_dump(array_merge($begin_array[4]));
71:
72: /* associative array with numeric keys, which will be re-indexed */
73: var_dump(array_merge($begin_array[5]));
74:
75: /* associative array with mixed keys and sub-array as element */
76: var_dump(array_merge($begin_array[6]));
77:
78: echo "\n*** Testing array_merge() with typecasting non-array to array ***\n";
79: var_dump(array_merge($begin_array[4], (array)"type1", (array)10, (array)12.34));
80:
81: echo "\n*** Testing error conditions ***";
82: /* Invalid argumens */
83: var_dump(array_merge());
84: var_dump(array_merge(100, 200));
85: var_dump(array_merge($begin_array[0], $begin_array[1], 100));
86: var_dump(array_merge($begin_array[0], $begin_array[1], $arr4));
87:
88: echo "Done\n";
89: ?>
90: --EXPECTF--
91: *** Testing array_merge() basic functionality ***
92:
93: --- Iteration 0 ---
94: -- Inner iteration 0 of Iteration 0 --
95: Array
96: (
97: )
98:
99: -- Inner iteration 1 of Iteration 0 --
100: Array
101: (
102: [0] => string
103: )
104:
105: -- Inner iteration 2 of Iteration 0 --
106: Array
107: (
108: [] => string
109: )
110:
111: -- Inner iteration 3 of Iteration 0 --
112: Array
113: (
114: [0] => 12
115: )
116:
117: -- Inner iteration 4 of Iteration 0 --
118: Array
119: (
120: [a] => 1
121: [b] => string
122: [c] =>
123: [d] => -2.344
124: )
125:
126: -- Inner iteration 5 of Iteration 0 --
127: Array
128: (
129: [0] => 1
130: [1] => string
131: [2] =>
132: [3] => -2.344
133: )
134:
135: -- Inner iteration 6 of Iteration 0 --
136: Array
137: (
138: [0] =>
139: [1] => Hi
140: [string] => hello
141: [2] => Array
142: (
143: [] => World
144: [-2.34] => a
145: [0] => b
146: )
147:
148: )
149:
150:
151: --- Iteration 1 ---
152: -- Inner iteration 0 of Iteration 1 --
153: Array
154: (
155: [0] => string
156: )
157:
158: -- Inner iteration 1 of Iteration 1 --
159: Array
160: (
161: [0] => string
162: [1] => string
163: )
164:
165: -- Inner iteration 2 of Iteration 1 --
166: Array
167: (
168: [0] => string
169: [] => string
170: )
171:
172: -- Inner iteration 3 of Iteration 1 --
173: Array
174: (
175: [0] => string
176: [1] => 12
177: )
178:
179: -- Inner iteration 4 of Iteration 1 --
180: Array
181: (
182: [0] => string
183: [a] => 1
184: [b] => string
185: [c] =>
186: [d] => -2.344
187: )
188:
189: -- Inner iteration 5 of Iteration 1 --
190: Array
191: (
192: [0] => string
193: [1] => 1
194: [2] => string
195: [3] =>
196: [4] => -2.344
197: )
198:
199: -- Inner iteration 6 of Iteration 1 --
200: Array
201: (
202: [0] => string
203: [1] =>
204: [2] => Hi
205: [string] => hello
206: [3] => Array
207: (
208: [] => World
209: [-2.34] => a
210: [0] => b
211: )
212:
213: )
214:
215:
216: --- Iteration 2 ---
217: -- Inner iteration 0 of Iteration 2 --
218: Array
219: (
220: [] => string
221: )
222:
223: -- Inner iteration 1 of Iteration 2 --
224: Array
225: (
226: [] => string
227: [0] => string
228: )
229:
230: -- Inner iteration 2 of Iteration 2 --
231: Array
232: (
233: [] => string
234: )
235:
236: -- Inner iteration 3 of Iteration 2 --
237: Array
238: (
239: [] => string
240: [0] => 12
241: )
242:
243: -- Inner iteration 4 of Iteration 2 --
244: Array
245: (
246: [] => string
247: [a] => 1
248: [b] => string
249: [c] =>
250: [d] => -2.344
251: )
252:
253: -- Inner iteration 5 of Iteration 2 --
254: Array
255: (
256: [] => string
257: [0] => 1
258: [1] => string
259: [2] =>
260: [3] => -2.344
261: )
262:
263: -- Inner iteration 6 of Iteration 2 --
264: Array
265: (
266: [] => string
267: [0] =>
268: [1] => Hi
269: [string] => hello
270: [2] => Array
271: (
272: [] => World
273: [-2.34] => a
274: [0] => b
275: )
276:
277: )
278:
279:
280: --- Iteration 3 ---
281: -- Inner iteration 0 of Iteration 3 --
282: Array
283: (
284: [0] => 12
285: )
286:
287: -- Inner iteration 1 of Iteration 3 --
288: Array
289: (
290: [0] => 12
291: [1] => string
292: )
293:
294: -- Inner iteration 2 of Iteration 3 --
295: Array
296: (
297: [0] => 12
298: [] => string
299: )
300:
301: -- Inner iteration 3 of Iteration 3 --
302: Array
303: (
304: [0] => 12
305: [1] => 12
306: )
307:
308: -- Inner iteration 4 of Iteration 3 --
309: Array
310: (
311: [0] => 12
312: [a] => 1
313: [b] => string
314: [c] =>
315: [d] => -2.344
316: )
317:
318: -- Inner iteration 5 of Iteration 3 --
319: Array
320: (
321: [0] => 12
322: [1] => 1
323: [2] => string
324: [3] =>
325: [4] => -2.344
326: )
327:
328: -- Inner iteration 6 of Iteration 3 --
329: Array
330: (
331: [0] => 12
332: [1] =>
333: [2] => Hi
334: [string] => hello
335: [3] => Array
336: (
337: [] => World
338: [-2.34] => a
339: [0] => b
340: )
341:
342: )
343:
344:
345: --- Iteration 4 ---
346: -- Inner iteration 0 of Iteration 4 --
347: Array
348: (
349: [a] => 1
350: [b] => string
351: [c] =>
352: [d] => -2.344
353: )
354:
355: -- Inner iteration 1 of Iteration 4 --
356: Array
357: (
358: [a] => 1
359: [b] => string
360: [c] =>
361: [d] => -2.344
362: [0] => string
363: )
364:
365: -- Inner iteration 2 of Iteration 4 --
366: Array
367: (
368: [a] => 1
369: [b] => string
370: [c] =>
371: [d] => -2.344
372: [] => string
373: )
374:
375: -- Inner iteration 3 of Iteration 4 --
376: Array
377: (
378: [a] => 1
379: [b] => string
380: [c] =>
381: [d] => -2.344
382: [0] => 12
383: )
384:
385: -- Inner iteration 4 of Iteration 4 --
386: Array
387: (
388: [a] => 1
389: [b] => string
390: [c] =>
391: [d] => -2.344
392: )
393:
394: -- Inner iteration 5 of Iteration 4 --
395: Array
396: (
397: [a] => 1
398: [b] => string
399: [c] =>
400: [d] => -2.344
401: [0] => 1
402: [1] => string
403: [2] =>
404: [3] => -2.344
405: )
406:
407: -- Inner iteration 6 of Iteration 4 --
408: Array
409: (
410: [a] => 1
411: [b] => string
412: [c] =>
413: [d] => -2.344
414: [0] =>
415: [1] => Hi
416: [string] => hello
417: [2] => Array
418: (
419: [] => World
420: [-2.34] => a
421: [0] => b
422: )
423:
424: )
425:
426:
427: --- Iteration 5 ---
428: -- Inner iteration 0 of Iteration 5 --
429: Array
430: (
431: [0] => 1
432: [1] => string
433: [2] =>
434: [3] => -2.344
435: )
436:
437: -- Inner iteration 1 of Iteration 5 --
438: Array
439: (
440: [0] => 1
441: [1] => string
442: [2] =>
443: [3] => -2.344
444: [4] => string
445: )
446:
447: -- Inner iteration 2 of Iteration 5 --
448: Array
449: (
450: [0] => 1
451: [1] => string
452: [2] =>
453: [3] => -2.344
454: [] => string
455: )
456:
457: -- Inner iteration 3 of Iteration 5 --
458: Array
459: (
460: [0] => 1
461: [1] => string
462: [2] =>
463: [3] => -2.344
464: [4] => 12
465: )
466:
467: -- Inner iteration 4 of Iteration 5 --
468: Array
469: (
470: [0] => 1
471: [1] => string
472: [2] =>
473: [3] => -2.344
474: [a] => 1
475: [b] => string
476: [c] =>
477: [d] => -2.344
478: )
479:
480: -- Inner iteration 5 of Iteration 5 --
481: Array
482: (
483: [0] => 1
484: [1] => string
485: [2] =>
486: [3] => -2.344
487: [4] => 1
488: [5] => string
489: [6] =>
490: [7] => -2.344
491: )
492:
493: -- Inner iteration 6 of Iteration 5 --
494: Array
495: (
496: [0] => 1
497: [1] => string
498: [2] =>
499: [3] => -2.344
500: [4] =>
501: [5] => Hi
502: [string] => hello
503: [6] => Array
504: (
505: [] => World
506: [-2.34] => a
507: [0] => b
508: )
509:
510: )
511:
512:
513: --- Iteration 6 ---
514: -- Inner iteration 0 of Iteration 6 --
515: Array
516: (
517: [0] =>
518: [1] => Hi
519: [string] => hello
520: [2] => Array
521: (
522: [] => World
523: [-2.34] => a
524: [0] => b
525: )
526:
527: )
528:
529: -- Inner iteration 1 of Iteration 6 --
530: Array
531: (
532: [0] =>
533: [1] => Hi
534: [string] => hello
535: [2] => Array
536: (
537: [] => World
538: [-2.34] => a
539: [0] => b
540: )
541:
542: [3] => string
543: )
544:
545: -- Inner iteration 2 of Iteration 6 --
546: Array
547: (
548: [0] =>
549: [1] => Hi
550: [string] => hello
551: [2] => Array
552: (
553: [] => World
554: [-2.34] => a
555: [0] => b
556: )
557:
558: [] => string
559: )
560:
561: -- Inner iteration 3 of Iteration 6 --
562: Array
563: (
564: [0] =>
565: [1] => Hi
566: [string] => hello
567: [2] => Array
568: (
569: [] => World
570: [-2.34] => a
571: [0] => b
572: )
573:
574: [3] => 12
575: )
576:
577: -- Inner iteration 4 of Iteration 6 --
578: Array
579: (
580: [0] =>
581: [1] => Hi
582: [string] => hello
583: [2] => Array
584: (
585: [] => World
586: [-2.34] => a
587: [0] => b
588: )
589:
590: [a] => 1
591: [b] => string
592: [c] =>
593: [d] => -2.344
594: )
595:
596: -- Inner iteration 5 of Iteration 6 --
597: Array
598: (
599: [0] =>
600: [1] => Hi
601: [string] => hello
602: [2] => Array
603: (
604: [] => World
605: [-2.34] => a
606: [0] => b
607: )
608:
609: [3] => 1
610: [4] => string
611: [5] =>
612: [6] => -2.344
613: )
614:
615: -- Inner iteration 6 of Iteration 6 --
616: Array
617: (
618: [0] =>
619: [1] => Hi
620: [string] => hello
621: [2] => Array
622: (
623: [] => World
624: [-2.34] => a
625: [0] => b
626: )
627:
628: [3] =>
629: [4] => Hi
630: [5] => Array
631: (
632: [] => World
633: [-2.34] => a
634: [0] => b
635: )
636:
637: )
638:
639: *** Testing array_merge() with three or more arrays ***
640: array(12) {
641: [0]=>
642: int(1)
643: [1]=>
644: string(6) "string"
645: [2]=>
646: NULL
647: [3]=>
648: float(-2.344)
649: ["a"]=>
650: int(1)
651: ["b"]=>
652: string(6) "string"
653: ["c"]=>
654: NULL
655: ["d"]=>
656: float(-2.344)
657: [4]=>
658: NULL
659: [5]=>
660: string(2) "Hi"
661: ["string"]=>
662: string(5) "hello"
663: [6]=>
664: array(3) {
665: [""]=>
666: string(5) "World"
667: ["-2.34"]=>
668: string(1) "a"
669: [0]=>
670: string(1) "b"
671: }
672: }
673: array(6) {
674: [0]=>
675: int(1)
676: [1]=>
677: string(6) "string"
678: [2]=>
679: NULL
680: [3]=>
681: float(-2.344)
682: [4]=>
683: string(12) "array on fly"
684: ["nullarray"]=>
685: array(0) {
686: }
687: }
688:
689: *** Testing single array argument ***
690: array(0) {
691: }
692: array(4) {
693: ["a"]=>
694: int(1)
695: ["b"]=>
696: string(6) "string"
697: ["c"]=>
698: NULL
699: ["d"]=>
700: float(-2.344)
701: }
702: array(4) {
703: [0]=>
704: int(1)
705: [1]=>
706: string(6) "string"
707: [2]=>
708: NULL
709: [3]=>
710: float(-2.344)
711: }
712: array(4) {
713: [0]=>
714: NULL
715: [1]=>
716: string(2) "Hi"
717: ["string"]=>
718: string(5) "hello"
719: [2]=>
720: array(3) {
721: [""]=>
722: string(5) "World"
723: ["-2.34"]=>
724: string(1) "a"
725: [0]=>
726: string(1) "b"
727: }
728: }
729:
730: *** Testing array_merge() with typecasting non-array to array ***
731: array(7) {
732: ["a"]=>
733: int(1)
734: ["b"]=>
735: string(6) "string"
736: ["c"]=>
737: NULL
738: ["d"]=>
739: float(-2.344)
740: [0]=>
741: string(5) "type1"
742: [1]=>
743: int(10)
744: [2]=>
745: float(12.34)
746: }
747:
748: *** Testing error conditions ***
749: Warning: array_merge() expects at least 1 parameter, 0 given in %s on line %d
750: NULL
751:
752: Warning: array_merge(): Argument #1 is not an array in %s on line %d
753: NULL
754:
755: Warning: array_merge(): Argument #3 is not an array in %s on line %d
756: NULL
757:
758: Notice: Undefined variable: arr4 in %s on line %d
759:
760: Warning: array_merge(): Argument #3 is not an array in %s on line %d
761: NULL
762: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>