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