1--TEST-- 2Test array_diff_assoc() function : usage variations - compare integers, floats and strings 3--FILE-- 4<?php 5/* Prototype : array array_diff_assoc(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 but do additional checks whether the keys are equal 8 * Source code: ext/standard/array.c 9 */ 10 11/* 12 * Test how array_diff_assoc compares integers, floats and string 13 */ 14 15echo "*** Testing array_diff_assoc() : usage variations ***\n"; 16$arr_default_int = array(1, 2, 3, 'a'); 17$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00, 'b'); 18$arr_string = array('1', '2', '3', 'c'); 19$arr_string_float = array('0' => '1.00', '1.00' => '2.00', '2.00' => '3.00', 'd'); 20 21echo "-- Result of comparing integers and floating point numbers: --\n"; 22var_dump(array_diff_assoc($arr_default_int, $arr_float)); 23var_dump(array_diff_assoc($arr_float, $arr_default_int)); 24 25echo "-- Result of comparing integers and strings containing an integers : --\n"; 26var_dump(array_diff_assoc($arr_default_int, $arr_string)); 27var_dump(array_diff_assoc($arr_string, $arr_default_int)); 28 29echo "-- Result of comparing integers and strings containing floating points : --\n"; 30var_dump(array_diff_assoc($arr_default_int, $arr_string_float)); 31var_dump(array_diff_assoc($arr_string_float, $arr_default_int)); 32 33echo "-- Result of comparing floating points and strings containing integers : --\n"; 34var_dump(array_diff_assoc($arr_float, $arr_string)); 35var_dump(array_diff_assoc($arr_string, $arr_float)); 36 37echo "-- Result of comparing floating points and strings containing floating point: --\n"; 38var_dump(array_diff_assoc($arr_float, $arr_string_float)); 39var_dump(array_diff_assoc($arr_string_float, $arr_float)); 40 41echo "-- Result of comparing strings containing integers and strings containing floating points : --\n"; 42var_dump(array_diff_assoc($arr_string, $arr_string_float)); 43var_dump(array_diff_assoc($arr_string_float, $arr_string)); 44 45echo "-- Result of comparing more than two arrays: --\n"; 46var_dump(array_diff_assoc($arr_default_int, $arr_float, $arr_string, $arr_string_float)); 47 48echo "Done"; 49?> 50--EXPECTF-- 51 52*** Testing array_diff_assoc() : usage variations *** 53-- Result of comparing integers and floating point numbers: -- 54array(1) { 55 [3]=> 56 string(1) "a" 57} 58array(1) { 59 [3]=> 60 string(1) "b" 61} 62-- Result of comparing integers and strings containing an integers : -- 63array(1) { 64 [3]=> 65 string(1) "a" 66} 67array(1) { 68 [3]=> 69 string(1) "c" 70} 71-- Result of comparing integers and strings containing floating points : -- 72array(4) { 73 [0]=> 74 int(1) 75 [1]=> 76 int(2) 77 [2]=> 78 int(3) 79 [3]=> 80 string(1) "a" 81} 82array(4) { 83 [0]=> 84 string(4) "1.00" 85 ["1.00"]=> 86 string(4) "2.00" 87 ["2.00"]=> 88 string(4) "3.00" 89 [1]=> 90 string(1) "d" 91} 92-- Result of comparing floating points and strings containing integers : -- 93array(1) { 94 [3]=> 95 string(1) "b" 96} 97array(1) { 98 [3]=> 99 string(1) "c" 100} 101-- Result of comparing floating points and strings containing floating point: -- 102array(4) { 103 [0]=> 104 float(1) 105 [1]=> 106 float(2) 107 [2]=> 108 float(3) 109 [3]=> 110 string(1) "b" 111} 112array(4) { 113 [0]=> 114 string(4) "1.00" 115 ["1.00"]=> 116 string(4) "2.00" 117 ["2.00"]=> 118 string(4) "3.00" 119 [1]=> 120 string(1) "d" 121} 122-- Result of comparing strings containing integers and strings containing floating points : -- 123array(4) { 124 [0]=> 125 string(1) "1" 126 [1]=> 127 string(1) "2" 128 [2]=> 129 string(1) "3" 130 [3]=> 131 string(1) "c" 132} 133array(4) { 134 [0]=> 135 string(4) "1.00" 136 ["1.00"]=> 137 string(4) "2.00" 138 ["2.00"]=> 139 string(4) "3.00" 140 [1]=> 141 string(1) "d" 142} 143-- Result of comparing more than two arrays: -- 144array(1) { 145 [3]=> 146 string(1) "a" 147} 148Done 149