1--TEST-- 2Test array_merge_recursive() function : usage variations - array with duplicate keys 3--FILE-- 4<?php 5/* Prototype : array array_merge_recursive(array $arr1[, array $...]) 6 * Description: Recursively merges elements from passed arrays into one array 7 * Source code: ext/standard/array.c 8*/ 9 10/* 11 * Testing the functionality of array_merge_recursive() by passing 12 * array having duplicate keys. 13*/ 14 15echo "*** Testing array_merge_recursive() : array with duplicate keys for \$arr1 argument ***\n"; 16 17/* initialize the array having duplicate keys */ 18// array with numeric keys 19$arr1_numeric_key = array( 1 => "one", 2 => "two", 2 => array(1, 2), 3 => "three", 1 => array("duplicate", 'strings')); 20// array with string keys 21$arr1_string_key = array("str1" => "hello", "str2" => 111, "str1" => "world", "str2" => 111.111); 22 23// initialize the second argument 24$arr2 = array("one", "str1" => "two", array("one", "two")); 25 26echo "-- With default argument --\n"; 27var_dump( array_merge_recursive($arr1_numeric_key) ); 28var_dump( array_merge_recursive($arr1_string_key) ); 29 30echo "-- With more arguments --\n"; 31var_dump( array_merge_recursive($arr1_numeric_key, $arr2) ); 32var_dump( array_merge_recursive($arr1_string_key, $arr2) ); 33 34echo "Done"; 35?> 36--EXPECTF-- 37*** Testing array_merge_recursive() : array with duplicate keys for $arr1 argument *** 38-- With default argument -- 39array(3) { 40 [0]=> 41 array(2) { 42 [0]=> 43 string(9) "duplicate" 44 [1]=> 45 string(7) "strings" 46 } 47 [1]=> 48 array(2) { 49 [0]=> 50 int(1) 51 [1]=> 52 int(2) 53 } 54 [2]=> 55 string(5) "three" 56} 57array(2) { 58 ["str1"]=> 59 string(5) "world" 60 ["str2"]=> 61 float(111.111) 62} 63-- With more arguments -- 64array(6) { 65 [0]=> 66 array(2) { 67 [0]=> 68 string(9) "duplicate" 69 [1]=> 70 string(7) "strings" 71 } 72 [1]=> 73 array(2) { 74 [0]=> 75 int(1) 76 [1]=> 77 int(2) 78 } 79 [2]=> 80 string(5) "three" 81 [3]=> 82 string(3) "one" 83 ["str1"]=> 84 string(3) "two" 85 [4]=> 86 array(2) { 87 [0]=> 88 string(3) "one" 89 [1]=> 90 string(3) "two" 91 } 92} 93array(4) { 94 ["str1"]=> 95 array(2) { 96 [0]=> 97 string(5) "world" 98 [1]=> 99 string(3) "two" 100 } 101 ["str2"]=> 102 float(111.111) 103 [0]=> 104 string(3) "one" 105 [1]=> 106 array(2) { 107 [0]=> 108 string(3) "one" 109 [1]=> 110 string(3) "two" 111 } 112} 113Done 114