1--TEST-- 2Test array_merge() function : usage variations - referenced variables 3--INI-- 4allow_call_time_pass_reference=on 5--FILE-- 6<?php 7/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) 8 * Description: Merges elements from passed arrays into one array 9 * Source code: ext/standard/array.c 10 */ 11 12/* Test array_merge() when: 13 * 1. Passed an array made up of referenced variables 14 * 2. Passed an array as the first argument and a reference to that array as the second. 15 */ 16 17echo "*** Testing array_merge() : usage variations ***\n"; 18 19$val1 = 'foo'; 20$val2 = 'bar'; 21$val3 = 'baz'; 22 23$arr1 = array(&$val1, &$val2, &$val3); 24$arr2 = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'); 25 26echo "\n-- Merge an array made up of referenced variables to an assoc. array --\n"; 27var_dump(array_merge($arr1, $arr2)); 28var_dump(array_merge($arr2, $arr1)); 29 30$val2 = 'hello world'; 31 32echo "\n-- Change \$val2 --\n"; 33var_dump(array_merge($arr1, $arr2)); 34var_dump(array_merge($arr2, $arr1)); 35 36echo "\n-- Merge an array and a reference to the first array --\n"; 37var_dump(array_merge($arr2, &$arr2)); 38 39echo "Done"; 40?> 41 42--EXPECTF-- 43*** Testing array_merge() : usage variations *** 44 45-- Merge an array made up of referenced variables to an assoc. array -- 46array(6) { 47 [0]=> 48 &string(3) "foo" 49 [1]=> 50 &string(3) "bar" 51 [2]=> 52 &string(3) "baz" 53 ["key1"]=> 54 string(4) "val1" 55 ["key2"]=> 56 string(4) "val2" 57 ["key3"]=> 58 string(4) "val3" 59} 60array(6) { 61 ["key1"]=> 62 string(4) "val1" 63 ["key2"]=> 64 string(4) "val2" 65 ["key3"]=> 66 string(4) "val3" 67 [0]=> 68 &string(3) "foo" 69 [1]=> 70 &string(3) "bar" 71 [2]=> 72 &string(3) "baz" 73} 74 75-- Change $val2 -- 76array(6) { 77 [0]=> 78 &string(3) "foo" 79 [1]=> 80 &string(11) "hello world" 81 [2]=> 82 &string(3) "baz" 83 ["key1"]=> 84 string(4) "val1" 85 ["key2"]=> 86 string(4) "val2" 87 ["key3"]=> 88 string(4) "val3" 89} 90array(6) { 91 ["key1"]=> 92 string(4) "val1" 93 ["key2"]=> 94 string(4) "val2" 95 ["key3"]=> 96 string(4) "val3" 97 [0]=> 98 &string(3) "foo" 99 [1]=> 100 &string(11) "hello world" 101 [2]=> 102 &string(3) "baz" 103} 104 105-- Merge an array and a reference to the first array -- 106array(3) { 107 ["key1"]=> 108 string(4) "val1" 109 ["key2"]=> 110 string(4) "val2" 111 ["key3"]=> 112 string(4) "val3" 113} 114Done 115