1--TEST-- 2Test array_diff_assoc() function : usage variations - strict string comparison check 3--FILE-- 4<?php 5/* 6 * Test how array_diff_assoc behaves 7 * 1. When comparing an array that has similar elements 8 * but has been created in a different order 9 * 2. When doing a strict comparison of string representation 10 */ 11 12echo "*** Testing array_diff_assoc() : usage variations ***\n"; 13 14$array = array ('zero', 15 1 => 1, 16 'two' => 2.00000000000001); 17 18$inputs = array ( 19 20//default keys => string values 21/*1*/ array('2.00000000000001', '1', 'zero', 'a'), 22 23//numeric keys => string values 24/*2*/ array(2 => '2.00000000000001', 25 1 => '1', 26 0 => 'zero', 27 3 => 'a'), 28 29//string keys => string values 30/*3*/ array('2' => '2.00000000000001', 31 '1' => '1', 32 '0' => 'zero', 33 '3' => 'a') , 34 35//default keys => numeric values 36/*4*/ array(2, 1, 0), 37 38//numeric keys => numeric values 39/*5*/ array(2 => 2, 40 1 => 1, 41 0 => 0), 42 43//string keys => numeric values 44/*6*/ array('two' => 2, 45 '1' => 1, 46 '0' => 0), 47 48//default keys => float values 49/*7*/ array(2.00000000000001, 1.00, 0.01E-9), 50 51//numeric keys => float values 52/*8*/ array(2 => 2.00000000000001, 53 1 => 1.00, 54 0 => 0.01E-9), 55 56//string keys => float values 57/*9*/ array ('two' => 2.00000000000001, 58 '1' => 1.00, 59 '0' =>0.01E-9) 60); 61 62// loop through each element of $inputs to check the behavior of array_diff_assoc 63$iterator = 1; 64foreach($inputs as $input) { 65 echo "\n-- Iteration $iterator --\n"; 66 var_dump(array_diff_assoc($array, $input)); 67 var_dump(array_diff_assoc($input, $array)); 68 $iterator++; 69}; 70echo "Done"; 71?> 72--EXPECT-- 73*** Testing array_diff_assoc() : usage variations *** 74 75-- Iteration 1 -- 76array(2) { 77 [0]=> 78 string(4) "zero" 79 ["two"]=> 80 float(2.00000000000001) 81} 82array(3) { 83 [0]=> 84 string(16) "2.00000000000001" 85 [2]=> 86 string(4) "zero" 87 [3]=> 88 string(1) "a" 89} 90 91-- Iteration 2 -- 92array(1) { 93 ["two"]=> 94 float(2.00000000000001) 95} 96array(2) { 97 [2]=> 98 string(16) "2.00000000000001" 99 [3]=> 100 string(1) "a" 101} 102 103-- Iteration 3 -- 104array(1) { 105 ["two"]=> 106 float(2.00000000000001) 107} 108array(2) { 109 [2]=> 110 string(16) "2.00000000000001" 111 [3]=> 112 string(1) "a" 113} 114 115-- Iteration 4 -- 116array(2) { 117 [0]=> 118 string(4) "zero" 119 ["two"]=> 120 float(2.00000000000001) 121} 122array(2) { 123 [0]=> 124 int(2) 125 [2]=> 126 int(0) 127} 128 129-- Iteration 5 -- 130array(2) { 131 [0]=> 132 string(4) "zero" 133 ["two"]=> 134 float(2.00000000000001) 135} 136array(2) { 137 [2]=> 138 int(2) 139 [0]=> 140 int(0) 141} 142 143-- Iteration 6 -- 144array(1) { 145 [0]=> 146 string(4) "zero" 147} 148array(1) { 149 [0]=> 150 int(0) 151} 152 153-- Iteration 7 -- 154array(2) { 155 [0]=> 156 string(4) "zero" 157 ["two"]=> 158 float(2.00000000000001) 159} 160array(2) { 161 [0]=> 162 float(2.00000000000001) 163 [2]=> 164 float(1.0E-11) 165} 166 167-- Iteration 8 -- 168array(2) { 169 [0]=> 170 string(4) "zero" 171 ["two"]=> 172 float(2.00000000000001) 173} 174array(2) { 175 [2]=> 176 float(2.00000000000001) 177 [0]=> 178 float(1.0E-11) 179} 180 181-- Iteration 9 -- 182array(1) { 183 [0]=> 184 string(4) "zero" 185} 186array(1) { 187 [0]=> 188 float(1.0E-11) 189} 190Done 191