--TEST-- Test array_merge_recursive() function : usage variations - associative array with different keys --FILE-- "0", 1 => array(1 => "one")), array(1 => "1", 2 => array(1 => "one", 2 => "two", 3 => 1, 4 => "4")), // arrays with float keys /*3*/ array(2.3333 => "float", 44.44 => array(1.1 => "float")), array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => array(1.1 => "f1"), 3333333.333333 => "f4"), // arrays with string keys /*5*/ array('\tHello' => array("hello", 'world'), '\v\fworld' => 2.2, 'pen\n' => 111), array("\tHello" => array("hello", 'world'), "\v\fworld" => 2.2, "pen\n" => 111), array("hello", $heredoc => array("heredoc", 'string'), "string"), // array with object, unset variable and resource variable /*8*/ array(new classA() => 11, @$unset_var => array("unset"), $fp => 'resource', 11, "hello") ); // initialise the second array $arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); // loop through each sub array of $arrays and check the behavior of array_merge_recursive() $iterator = 1; foreach($arrays as $arr1) { echo "-- Iteration $iterator --\n"; // with default argument echo "-- With default argument --\n"; var_dump( array_merge_recursive($arr1) ); // with more arguments echo "-- With more arguments --\n"; var_dump( array_merge_recursive($arr1, $arr2) ); $iterator++; } // close the file resource used fclose($fp); echo "Done"; ?> --EXPECTF-- *** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument *** Warning: Illegal offset type in %s on line %d Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d -- Iteration 1 -- -- With default argument -- array(2) { [0]=> string(1) "0" [1]=> array(1) { [1]=> string(3) "one" } } -- With more arguments -- array(6) { [0]=> string(1) "0" [1]=> array(1) { [1]=> string(3) "one" } [2]=> string(3) "one" [3]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 2 -- -- With default argument -- array(2) { [0]=> string(1) "1" [1]=> array(4) { [1]=> string(3) "one" [2]=> string(3) "two" [3]=> int(1) [4]=> string(1) "4" } } -- With more arguments -- array(6) { [0]=> string(1) "1" [1]=> array(4) { [1]=> string(3) "one" [2]=> string(3) "two" [3]=> int(1) [4]=> string(1) "4" } [2]=> string(3) "one" [3]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 3 -- -- With default argument -- array(2) { [0]=> string(5) "float" [1]=> array(1) { [1]=> string(5) "float" } } -- With more arguments -- array(6) { [0]=> string(5) "float" [1]=> array(1) { [1]=> string(5) "float" } [2]=> string(3) "one" [3]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 4 -- -- With default argument -- array(4) { [0]=> string(2) "f1" [1]=> string(2) "f2" [2]=> array(1) { [1]=> string(2) "f1" } [3]=> string(2) "f4" } -- With more arguments -- array(8) { [0]=> string(2) "f1" [1]=> string(2) "f2" [2]=> array(1) { [1]=> string(2) "f1" } [3]=> string(2) "f4" [4]=> string(3) "one" [5]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 5 -- -- With default argument -- array(3) { ["\tHello"]=> array(2) { [0]=> string(5) "hello" [1]=> string(5) "world" } ["\v\fworld"]=> float(2.2) ["pen\n"]=> int(111) } -- With more arguments -- array(7) { ["\tHello"]=> array(2) { [0]=> string(5) "hello" [1]=> string(5) "world" } ["\v\fworld"]=> float(2.2) ["pen\n"]=> int(111) [0]=> string(3) "one" [1]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 6 -- -- With default argument -- array(3) { [" Hello"]=> array(2) { [0]=> string(5) "hello" [1]=> string(5) "world" } [" world"]=> float(2.2) ["pen "]=> int(111) } -- With more arguments -- array(7) { [" Hello"]=> array(2) { [0]=> string(5) "hello" [1]=> string(5) "world" } [" world"]=> float(2.2) ["pen "]=> int(111) [0]=> string(3) "one" [1]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 7 -- -- With default argument -- array(3) { [0]=> string(5) "hello" ["Hello world"]=> array(2) { [0]=> string(7) "heredoc" [1]=> string(6) "string" } [1]=> string(6) "string" } -- With more arguments -- array(7) { [0]=> string(5) "hello" ["Hello world"]=> array(2) { [0]=> string(7) "heredoc" [1]=> string(6) "string" } [1]=> string(6) "string" [2]=> string(3) "one" [3]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } -- Iteration 8 -- -- With default argument -- array(4) { [""]=> array(1) { [0]=> string(5) "unset" } [0]=> string(8) "resource" [1]=> int(11) [2]=> string(5) "hello" } -- With more arguments -- array(8) { [""]=> array(1) { [0]=> string(5) "unset" } [0]=> string(8) "resource" [1]=> int(11) [2]=> string(5) "hello" [3]=> string(3) "one" [4]=> int(2) ["string"]=> string(5) "hello" ["array"]=> array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" } } Done