1--TEST-- 2Test array_diff() function : usage variations - arrays containing referenced variables 3--FILE-- 4<?php 5/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) 6 * Description: Returns the entries of $arr1 that have values which are not 7 * present in any of the others arguments. 8 * Source code: ext/standard/array.c 9 */ 10 11/* 12 * Test how array_diff compares arrays that 13 * 1. Contain referenced variables 14 * 2. Have been referenced to each other 15 */ 16 17echo "*** Testing array_diff() : usage variations ***\n"; 18$a = 'a'; 19 20$arr1 = array ("&$a", 'b', 'c'); 21$arr2 = array (1, 2, 3); 22echo "-- Basic Comparison --\n"; 23var_dump(array_diff($arr1, $arr2)); 24var_dump(array_diff($arr2, $arr1)); 25 26$a = 1; 27 28echo "-- \$a changed --\n"; 29var_dump(array_diff($arr1, $arr2)); 30var_dump(array_diff($arr2, $arr1)); 31 32 33$arr2 = &$arr1; 34echo "-- Arrays referenced to each other --\n"; 35var_dump(array_diff($arr1, $arr2)); 36var_dump(array_diff($arr2, $arr1)); 37 38 39$arr1 = array('x', 'y', 'z'); 40echo "-- \$arr1 changed --\n"; 41var_dump(array_diff($arr1, $arr2)); 42var_dump(array_diff($arr2, $arr1)); 43 44 45echo "Done"; 46?> 47--EXPECT-- 48*** Testing array_diff() : usage variations *** 49-- Basic Comparison -- 50array(3) { 51 [0]=> 52 string(2) "&a" 53 [1]=> 54 string(1) "b" 55 [2]=> 56 string(1) "c" 57} 58array(3) { 59 [0]=> 60 int(1) 61 [1]=> 62 int(2) 63 [2]=> 64 int(3) 65} 66-- $a changed -- 67array(3) { 68 [0]=> 69 string(2) "&a" 70 [1]=> 71 string(1) "b" 72 [2]=> 73 string(1) "c" 74} 75array(3) { 76 [0]=> 77 int(1) 78 [1]=> 79 int(2) 80 [2]=> 81 int(3) 82} 83-- Arrays referenced to each other -- 84array(0) { 85} 86array(0) { 87} 88-- $arr1 changed -- 89array(0) { 90} 91array(0) { 92} 93Done 94