1--TEST-- 2Test of the array_diff_key() and array_diff_ukey() 3--FILE-- 4<?php 5$a = array(1, 6, 2, -20, 15, 1200, -2500); 6$b = array(0, 7, 2, -20, 11, 1100, -2500); 7$c = array(0, 6, 2, -20, 19, 1000, -2500); 8$d = array(3, 8,-2, -20, 14, 900, -2600); 9$a_f = array_flip($a); 10$b_f = array_flip($b); 11$c_f = array_flip($c); 12$d_f = array_flip($d); 13$i = 1; 14/* give nicer values */ 15foreach ($a_f as $k=> &$a_f_el) { $a_f_el =$k*2;} 16foreach ($b_f as $k=> &$b_f_el) { $b_f_el =$k*2;} 17foreach ($c_f as $k=> &$c_f_el) { $c_f_el =$k*2;} 18foreach ($d_f as $k=> &$d_f_el) { $d_f_el =$k*2;} 19 20echo "------ Test $i --------\n";$i++;// 1 21var_dump(array_diff_key($a_f, $b_f));// keys -> 1, 6, 15, 1200 22var_dump(array_diff_ukey($a_f, $b_f, "comp_func"));// 1, 6, 15, 1200 23 24echo "------ Test $i --------\n";$i++;// 2 25var_dump(array_diff_key($a_f, $c_f));// keys -> 1, 15, 1200 26var_dump(array_diff_ukey($a_f, $c_f, "comp_func"));// 1, 15, 1200 27 28echo "------ Test $i --------\n";$i++;// 3 29var_dump(array_diff_key($a_f, $d_f));// 1, 6, 2, 15, 1200, -2500 30var_dump(array_diff_ukey($a_f, $d_f, "comp_func"));// 1, 6, 2, 15, 1200, -2500 31 32echo "------ Test $i --------\n";$i++;// 4 33var_dump(array_diff_key($a_f, $b_f, $c_f));// 1, 15, 1200 34var_dump(array_diff_ukey($a_f, $b_f, $c_f, "comp_func"));// 1, 15, 1200 35 36echo "------ Test $i --------\n";$i++;// 5 37var_dump(array_diff_key($a_f, $b_f, $d_f));// 1, 6, 15, 1200 38var_dump(array_diff_ukey($a_f, $b_f, $d_f, "comp_func"));// 1, 6, 15, 1200 39 40 41echo "------ Test $i --------\n";$i++;// 6 42var_dump(array_diff_key($a_f, $b_f, $c_f, $d_f));// 1, 15, 1200 43var_dump(array_diff_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));//1, 15, 1200 44 45 46echo "------ Test $i --------\n";$i++;// 7 47var_dump(array_diff_key($b_f, $c_f));// 7, 11, 1100 48var_dump(array_diff_ukey($b_f, $c_f, "comp_func"));//7, 11, 1100 49 50echo "------ Test $i --------\n";$i++;// 8 51var_dump(array_diff_key($b_f, $d_f));//0, 7, 2, 11, 1100, -2500 52var_dump(array_diff_ukey($b_f, $d_f, "comp_func"));//0, 7, 2, 11, 1100, -2500 53 54 55echo "------ Test $i --------\n";$i++;// 9 56var_dump(array_diff_key($b_f, $c_f, $d_f));// 7, 11, 1100 57var_dump(array_diff_ukey($b_f, $c_f, $d_f, "comp_func"));// 7, 11, 1000 58 59function comp_func($a, $b) { 60 if ($a === $b) return 0; 61 return ($a > $b)? 1:-1; 62 63} 64?> 65--EXPECT-- 66------ Test 1 -------- 67array(4) { 68 [1]=> 69 int(2) 70 [6]=> 71 int(12) 72 [15]=> 73 int(30) 74 [1200]=> 75 int(2400) 76} 77array(4) { 78 [1]=> 79 int(2) 80 [6]=> 81 int(12) 82 [15]=> 83 int(30) 84 [1200]=> 85 int(2400) 86} 87------ Test 2 -------- 88array(3) { 89 [1]=> 90 int(2) 91 [15]=> 92 int(30) 93 [1200]=> 94 int(2400) 95} 96array(3) { 97 [1]=> 98 int(2) 99 [15]=> 100 int(30) 101 [1200]=> 102 int(2400) 103} 104------ Test 3 -------- 105array(6) { 106 [1]=> 107 int(2) 108 [6]=> 109 int(12) 110 [2]=> 111 int(4) 112 [15]=> 113 int(30) 114 [1200]=> 115 int(2400) 116 [-2500]=> 117 &int(-5000) 118} 119array(6) { 120 [1]=> 121 int(2) 122 [6]=> 123 int(12) 124 [2]=> 125 int(4) 126 [15]=> 127 int(30) 128 [1200]=> 129 int(2400) 130 [-2500]=> 131 &int(-5000) 132} 133------ Test 4 -------- 134array(3) { 135 [1]=> 136 int(2) 137 [15]=> 138 int(30) 139 [1200]=> 140 int(2400) 141} 142array(3) { 143 [1]=> 144 int(2) 145 [15]=> 146 int(30) 147 [1200]=> 148 int(2400) 149} 150------ Test 5 -------- 151array(4) { 152 [1]=> 153 int(2) 154 [6]=> 155 int(12) 156 [15]=> 157 int(30) 158 [1200]=> 159 int(2400) 160} 161array(4) { 162 [1]=> 163 int(2) 164 [6]=> 165 int(12) 166 [15]=> 167 int(30) 168 [1200]=> 169 int(2400) 170} 171------ Test 6 -------- 172array(3) { 173 [1]=> 174 int(2) 175 [15]=> 176 int(30) 177 [1200]=> 178 int(2400) 179} 180array(3) { 181 [1]=> 182 int(2) 183 [15]=> 184 int(30) 185 [1200]=> 186 int(2400) 187} 188------ Test 7 -------- 189array(3) { 190 [7]=> 191 int(14) 192 [11]=> 193 int(22) 194 [1100]=> 195 int(2200) 196} 197array(3) { 198 [7]=> 199 int(14) 200 [11]=> 201 int(22) 202 [1100]=> 203 int(2200) 204} 205------ Test 8 -------- 206array(6) { 207 [0]=> 208 int(0) 209 [7]=> 210 int(14) 211 [2]=> 212 int(4) 213 [11]=> 214 int(22) 215 [1100]=> 216 int(2200) 217 [-2500]=> 218 &int(-5000) 219} 220array(6) { 221 [0]=> 222 int(0) 223 [7]=> 224 int(14) 225 [2]=> 226 int(4) 227 [11]=> 228 int(22) 229 [1100]=> 230 int(2200) 231 [-2500]=> 232 &int(-5000) 233} 234------ Test 9 -------- 235array(3) { 236 [7]=> 237 int(14) 238 [11]=> 239 int(22) 240 [1100]=> 241 int(2200) 242} 243array(3) { 244 [7]=> 245 int(14) 246 [11]=> 247 int(22) 248 [1100]=> 249 int(2200) 250} 251