1--TEST-- 2Test array_diff_assoc() function : variation - array containing different data types 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 indexed arrays containing different data types 13 */ 14 15echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; 16 17$array = array(1, 2, 3); 18 19//get an unset variable 20$unset_var = 10; 21unset ($unset_var); 22 23// get a class 24class classA 25{ 26 public function __toString() { 27 return "Class A object"; 28 } 29} 30 31// heredoc string 32$heredoc = <<<EOT 33hello world 34EOT; 35 36//array of different data types to be passed to $arr1 argument 37$inputs = array( 38 39 // int data 40/*1*/ 41'int' => array( 42 0, 43 1, 44 12345, 45 -2345), 46 47 // float data 48/*2*/ 49'float' => array( 50 10.5, 51 -10.5, 52 12.3456789000e10, 53 12.3456789000E-10, 54 .5), 55 56 // null data 57/*3*/ 58'null' => array( 59 NULL, 60 null), 61 62 // boolean data 63/*4*/ 64'bool' => array( 65 true, 66 false, 67 TRUE, 68 FALSE), 69 70 // empty data 71/*5*/ 72'empty' => array( 73 "", 74 ''), 75 76 // string data 77/*6*/ 78'string' => array( 79 "string", 80 'string', 81 $heredoc), 82 83 // binary data 84/*7*/ 85'binary' => array( 86 b"binary", 87 (binary)"binary"), 88 89 // object data 90/*8*/ 91'object' => array( 92 new classA()), 93 94 // undefined data 95/*9*/ 96'undefined' => array( 97 @$undefined_var), 98 99 // unset data 100/*10*/ 101'unset' => array( 102 @$unset_var), 103); 104 105// loop through each element of $inputs to check the behavior of array_diff_assoc 106$iterator = 1; 107foreach($inputs as $key => $input) { 108 echo "\n-- Iteration $iterator --\n"; 109 var_dump( array_diff_assoc($input, $array)); 110 $iterator++; 111}; 112echo "Done"; 113?> 114--EXPECTF-- 115*** Testing array_diff_assoc() : usage variations *** 116 117-- Iteration 1 -- 118array(4) { 119 [0]=> 120 int(0) 121 [1]=> 122 int(1) 123 [2]=> 124 int(12345) 125 [3]=> 126 int(-2345) 127} 128 129-- Iteration 2 -- 130array(5) { 131 [0]=> 132 float(10.5) 133 [1]=> 134 float(-10.5) 135 [2]=> 136 float(123456789000) 137 [3]=> 138 float(1.23456789E-9) 139 [4]=> 140 float(0.5) 141} 142 143-- Iteration 3 -- 144array(2) { 145 [0]=> 146 NULL 147 [1]=> 148 NULL 149} 150 151-- Iteration 4 -- 152array(3) { 153 [1]=> 154 bool(false) 155 [2]=> 156 bool(true) 157 [3]=> 158 bool(false) 159} 160 161-- Iteration 5 -- 162array(2) { 163 [0]=> 164 string(0) "" 165 [1]=> 166 string(0) "" 167} 168 169-- Iteration 6 -- 170array(3) { 171 [0]=> 172 string(6) "string" 173 [1]=> 174 string(6) "string" 175 [2]=> 176 string(11) "hello world" 177} 178 179-- Iteration 7 -- 180array(2) { 181 [0]=> 182 string(6) "binary" 183 [1]=> 184 string(6) "binary" 185} 186 187-- Iteration 8 -- 188array(1) { 189 [0]=> 190 object(classA)#%d (0) { 191 } 192} 193 194-- Iteration 9 -- 195array(1) { 196 [0]=> 197 NULL 198} 199 200-- Iteration 10 -- 201array(1) { 202 [0]=> 203 NULL 204} 205Done 206