1--TEST-- 2Test array_diff() function : usage variations - associative arrays containing different data types 3--FILE-- 4<?php 5/* 6 * Test array_diff() with associative arrays containing different data types as values 7 */ 8 9echo "*** Testing array_diff() : usage variations ***\n"; 10 11$array = array('a' => '1', 'b' => '2', 'c' => '3'); 12 13// get an unset variable 14$unset_var = 10; 15unset ($unset_var); 16 17// get a resource variable 18$fp = fopen(__FILE__, "r"); 19 20// get a class 21class classA 22{ 23 public function __toString() { 24 return "Class A object"; 25 } 26} 27 28// get a heredoc string 29$heredoc = <<<EOT 30Hello world 31EOT; 32 33// associative arrays with different values 34$inputs = array ( 35 // arrays with integer values 36/*1*/ array('0' => 0, '1' => 0), 37 array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), 38 39 // arrays with float values 40/*3*/ array("float1" => 2.3333, "float2" => 2.3333), 41 array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), 42 43 // arrays with string values 44/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3 => "\tHello"), 45 array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3 => '\tHello'), 46 array(1 => "hello", "heredoc" => $heredoc, $heredoc), 47 48 // array with object, unset variable and resource variable 49/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), 50); 51 52// loop through each sub-array of $inputs to check the behavior of array_unique() 53$iterator = 1; 54foreach($inputs as $input) { 55 echo "-- Iteration $iterator --\n"; 56 var_dump( array_diff($array, $input) ); 57 var_dump( array_diff($input, $array) ); 58 $iterator++; 59} 60 61fclose($fp); 62 63echo "Done"; 64?> 65--EXPECTF-- 66*** Testing array_diff() : usage variations *** 67-- Iteration 1 -- 68array(3) { 69 ["a"]=> 70 string(1) "1" 71 ["b"]=> 72 string(1) "2" 73 ["c"]=> 74 string(1) "3" 75} 76array(2) { 77 [0]=> 78 int(0) 79 [1]=> 80 int(0) 81} 82-- Iteration 2 -- 83array(1) { 84 ["c"]=> 85 string(1) "3" 86} 87array(0) { 88} 89-- Iteration 3 -- 90array(3) { 91 ["a"]=> 92 string(1) "1" 93 ["b"]=> 94 string(1) "2" 95 ["c"]=> 96 string(1) "3" 97} 98array(2) { 99 ["float1"]=> 100 float(2.3333) 101 ["float2"]=> 102 float(2.3333) 103} 104-- Iteration 4 -- 105array(3) { 106 ["a"]=> 107 string(1) "1" 108 ["b"]=> 109 string(1) "2" 110 ["c"]=> 111 string(1) "3" 112} 113array(4) { 114 ["f1"]=> 115 float(1.2) 116 ["f2"]=> 117 float(3.33) 118 [3]=> 119 float(4.89999922839999) 120 ["f4"]=> 121 float(1.2) 122} 123-- Iteration 5 -- 124array(3) { 125 ["a"]=> 126 string(1) "1" 127 ["b"]=> 128 string(1) "2" 129 ["c"]=> 130 string(1) "3" 131} 132array(4) { 133 [111]=> 134 string(6) " Hello" 135 ["red"]=> 136 string(6) "col or" 137 [2]=> 138 string(7) "world" 139 [3]=> 140 string(6) " Hello" 141} 142-- Iteration 6 -- 143array(3) { 144 ["a"]=> 145 string(1) "1" 146 ["b"]=> 147 string(1) "2" 148 ["c"]=> 149 string(1) "3" 150} 151array(4) { 152 [111]=> 153 string(7) "\tHello" 154 ["red"]=> 155 string(7) "col\tor" 156 [2]=> 157 string(9) "\v\fworld" 158 [3]=> 159 string(7) "\tHello" 160} 161-- Iteration 7 -- 162array(3) { 163 ["a"]=> 164 string(1) "1" 165 ["b"]=> 166 string(1) "2" 167 ["c"]=> 168 string(1) "3" 169} 170array(3) { 171 [1]=> 172 string(5) "hello" 173 ["heredoc"]=> 174 string(11) "Hello world" 175 [2]=> 176 string(11) "Hello world" 177} 178-- Iteration 8 -- 179array(3) { 180 ["a"]=> 181 string(1) "1" 182 ["b"]=> 183 string(1) "2" 184 ["c"]=> 185 string(1) "3" 186} 187array(5) { 188 [11]=> 189 object(classA)#%d (0) { 190 } 191 ["unset"]=> 192 NULL 193 ["resource"]=> 194 resource(%d) of type (stream) 195 [12]=> 196 object(classA)#%d (0) { 197 } 198 [13]=> 199 resource(%d) of type (stream) 200} 201Done 202