1--TEST-- 2Test array_diff() function : basic functionality 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 present 7 * in any of the others arguments. 8 * Source code: ext/standard/array.c 9 */ 10 11/* 12 * Test basic functionality of array_diff 13 */ 14 15echo "*** Testing array_diff() : basic functionality ***\n"; 16 17//Test indexed array with integers as elements 18$array_int1 = array (1, 2, 3, 4); 19$array_int2 = array (3, 4, 5, 6); 20 21echo "-- Test indexed array with integers as elements --\n"; 22var_dump(array_diff($array_int1, $array_int2)); 23var_dump(array_diff($array_int2, $array_int1)); 24 25 26//Test indexed array with strings as elements 27$array_string1 = array ('one', 'two', 'three', 'four'); 28$array_string2 = array ('three', 'four', 'five', 'six'); 29 30echo "-- Test indexed array with strings as elements --\n"; 31var_dump(array_diff($array_string1, $array_string2)); 32var_dump(array_diff($array_string2, $array_string1)); 33 34//Test associative array with strings as keys and integers as elements 35$array_assoc_int1 = array ('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4); 36$array_assoc_int2 = array ('three' => 3, 'four' => 4, 'five' => 5, 'six' => 6); 37 38echo "-- Test associative array with strings as keys and integers as elements --\n"; 39var_dump(array_diff($array_assoc_int1, $array_assoc_int2)); 40var_dump(array_diff($array_assoc_int2, $array_assoc_int1)); 41 42//Test associative array with strings as keys and elements 43$array_assoc_str1 = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois', 'four' => 'quatre'); 44$array_assoc_str2 = array ('three' => 'trois', 'four' => 'quatre', 'five' => 'cinq', 'six' => 'six'); 45 46echo "-- Test associative array with strings as keys and integers as elements --\n"; 47var_dump(array_diff($array_assoc_str1, $array_assoc_str2)); 48var_dump(array_diff($array_assoc_str2, $array_assoc_str1)); 49 50echo "-- Test array_diff with more than 2 arguments --\n"; 51var_dump(array_diff($array_int1, $array_int2, $array_string1, $array_string2)); 52 53echo "Done"; 54?> 55--EXPECT-- 56*** Testing array_diff() : basic functionality *** 57-- Test indexed array with integers as elements -- 58array(2) { 59 [0]=> 60 int(1) 61 [1]=> 62 int(2) 63} 64array(2) { 65 [2]=> 66 int(5) 67 [3]=> 68 int(6) 69} 70-- Test indexed array with strings as elements -- 71array(2) { 72 [0]=> 73 string(3) "one" 74 [1]=> 75 string(3) "two" 76} 77array(2) { 78 [2]=> 79 string(4) "five" 80 [3]=> 81 string(3) "six" 82} 83-- Test associative array with strings as keys and integers as elements -- 84array(2) { 85 ["one"]=> 86 int(1) 87 ["two"]=> 88 int(2) 89} 90array(2) { 91 ["five"]=> 92 int(5) 93 ["six"]=> 94 int(6) 95} 96-- Test associative array with strings as keys and integers as elements -- 97array(2) { 98 ["one"]=> 99 string(2) "un" 100 ["two"]=> 101 string(4) "deux" 102} 103array(2) { 104 ["five"]=> 105 string(4) "cinq" 106 ["six"]=> 107 string(3) "six" 108} 109-- Test array_diff with more than 2 arguments -- 110array(2) { 111 [0]=> 112 int(1) 113 [1]=> 114 int(2) 115} 116Done 117