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